function selectElementContents(el) {
var body = document.body, range, sel;
if (document.createRange && window.getSelection) {
range = document.createRange();
sel = window.getSelection();
sel.removeAllRanges();
try {
range.selectNodeContents(el);
sel.addRange(range);
} catch (e) {
range.selectNode(el);
sel.addRange(range);
}
} else if (body.createTextRange) {
range = body.createTextRange();
range.moveToElementText(el);
range.select();
}
}
document.execCommand("copy");
function copy(elem, type = 'input') {
let text = '';
//define the target text;
if (type === 'input')
text = $(elem).val();
else
text = $(elem).text();
//append input element to body to store target text
var temp = $("<input>");
$("body").append(temp);
temp.val(text).select(); //select text to make it able executable
document.execCommand("copy"); //run the copy command.
temp.remove(); // remove input element from DOM after Execute copy command.
// add effect to element to user notice copy execution.
let notify = $('<i class="fas fa-keyboard fa-2x text-info bg-light">Copied!!</i>');
$(elem).closest('div').find('.fas').prepend(notify);
notify.css('display', 'block')
notify.fadeOut(2000);
}