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
pyinstaller.exe --onedir --hidden-import FileDialog --windowed --noupx new-app.py
Thank you!
2
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.
Thank you!
5
0
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-27 22:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-27 22:45:24 income of a web developer
-
Other 2022-03-27 22:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-27 22:30:45 rick roll embed code
-
Other 2022-03-27 22:20:08 Circuit_04_Potentiometer
-
Other 2022-03-27 22:20:05 iterative power
-
Other 2022-03-27 22:15:11 flutter run all
-
Other 2022-03-27 22:10:05 when is karlson release
-
Other 2022-03-27 22:10:02 wp .htaccess example
-
Other 2022-03-27 22:00:08 bash pause in file read line by line