+ 2
[SOLVED] What is appendChild() in JavaScript?
Can any one explain?
3 Réponses
+ 13
imagine you have this div
<div id="my-div"></div>
and now you want to dynamically add content into it
append child is one of the ways to do so:
in JavaScript:
var myDiv = document.getElementById("my-div");
// create a new span element
var mySpan = document.createElement("span");
mySpan.innerHTML = "hello, i'm a span";
myDiv.appendChild(mySpan);
and now your DOM basically looks like this:
<div id="my-div">
<span>
hello, i'm a span
</span>
</div>
for more you can refer to here
https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
&&
https://www.w3schools.com/jsref/met_node_appendchild.asp
+ 7
no probs ;)
marking as [SOLVED] for others who might need it
+ 1
thank you