Return to Snippet

Revision: 62346
at February 18, 2013 04:10 by flamboyanz


Initial Code
$("<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);
    
});

Initial URL

                                

Initial Description
Javascript DOM Create Element

Initial Title
Javascript DOM Create Element

Initial Tags
DOM

Initial Language
JavaScript