+ 2

[SOLVED] What is appendChild() in JavaScript?

Can any one explain?

24th Feb 2018, 10:38 AM
Vikesh Patil
3 Antworten
+ 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
24th Feb 2018, 10:48 AM
Burey
Burey - avatar
+ 7
no probs ;) marking as [SOLVED] for others who might need it
24th Feb 2018, 11:44 AM
Burey
Burey - avatar
+ 1
thank you
24th Feb 2018, 11:34 AM
Vikesh Patil