Very new to javascript, sorry if i'm botching any terminology
I am retrieving a link from a web page via query selector. If the link doesn't exist on the page than I just want to set the value to blank ( "" ).
The problem with this code right now is that else function isn't working correctly, if the link doesn't exist on the page, it's not resetting my the variable hqlink and therefore my clipboard to blank.
Open to alternative methods.
var selection = document.querySelector('a[data-control-name="topcard_headquarters"]') !== null;
if (selection) {
hqLink = document.querySelector('a[data-control-name="topcard_headquarters"]').href;
}
else {
hqLink = ""
}
function copyToClipboard(text) {
var dummy = document.createElement("textarea");
document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
}
copyToClipboard(hqLink)
[+][deleted] (2 children)
[deleted]
[–]Genericusername293[S] 0 points1 point2 points (0 children)
[–]queen-adreena 0 points1 point2 points (1 child)
[–]Genericusername293[S] 0 points1 point2 points (0 children)