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);

4.5
2
Joanis 70 points

                                    pyinstaller.exe --onedir --hidden-import FileDialog --windowed --noupx new-app.py

4.5 (2 Votes)
0
4
5

                                    .appendChild
The [.appendChild] function needs the first parameter as a Node.

Any one of the following interface is considered a Node:

Document
Element
Attr
CharacterData
ProcessingInstruction
DocumentFragment
DocumentType
Notation
Anything that is not one of the above is not considered a Node. Therefore, when you pass an object or a string (the response), the following error is raised:

TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

The response returned by ajax request is most likely an Object.

JSON.stringify will transform an Object into String.

Both are not one of the listed interface.

4 (5 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source