Answers for "Uncaught DOMException: Failed to execute"

1

uncaught typeerror: failed to execute

#I could have sworn that I was using appendChild properly but, alas, I wasn’t.
#Instead of passing a node to appendChild, I was passing a string.

var link = '<a class="wplauncher-link"> Example Link </a>';
var body = document.getElementsByTagName('body')[0].appendChild(link);

#Instead, I should have created the link element first, added HTML to it, 
#and then run appendChild. This is illustrated in the code below, which WORKS:

var link = document.createElement('a');
link.className = 'wplauncher-link';
link.innerHTML = 'Example Link';
document.body.appendChild(link);

#If you need to add a string of HTML that is more complex than a link, 
#I suggest using the insertAdjacentHTML method. An example of this is visible 
#below:

var link = '<a class="wplauncher-link"> Example Link </a>';
document.body.insertAdjacentHTML('beforeend',link);
Posted by: Guest on June-02-2021

Code answers related to "Uncaught DOMException: Failed to execute"

Browse Popular Code Answers by Language