Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: appendchild append div not working

Tags:

javascript

i want to dynamically add div element to my page.searching around including Stackoverflow gives me this sample code:

var main = document.getElementById('MasterContainer'); //manually defined div with this id 
var div = document.createElement('div');
div.setAttribute("id","container1");
main.appendChild(div);

note: its inside a document.ready function.

and the result does not contain container1 div.

like image 693
user1229351 Avatar asked Sep 16 '26 23:09

user1229351


1 Answers

The code should be fine, check if the element with id #MasterContaienr is on the page and the name has been write well

like image 92
Lwyrn Avatar answered Sep 19 '26 13:09

Lwyrn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!