/ Published in: JavaScript
Javascript DOM Create Element
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$("<a/>", { id: 'example-link', href: 'http://www.example.com/', text: 'Example Page' }).appendTo("body"); var myRow = document.createElement("p"); myRow.class = "myClass"; myRow.id = 'mycustomdiv' myRow.innerHTML = elements; var textcontent = document.createTextNode('Hello All') myRow.appendChild(textcontent) document.getElementsByTagName('body')[0].appendChild(myRow); document.getElementById("myContainer").appendChild(myRow); _________ var elem = document.getElementById('container'); var child = elem.children[0]; var child = elem.firstElementChild;//== children[0] var child = elem.childNodes[0];//or childNodes[1] var child = elem.childNodes;//treat as Nodelist var child = elem.firstChild; console.log(elem.childNodes[1]); console.log(elem.children[0]); console.log(elem.firstElementChild); // CloneNode $('li').bind('click', function(){ var select = $(this).find('section') var dupeSelect = select[0].cloneNode(true); $('#uphole').html(dupeSelect); });