Javascript createElement and appendchild in one step -


i want create element , append other elements in 1 step.

var header = document.createelement("thead").appendchild(document.createelement("tr")); 

why code outputs tr , not thead?

when use code correct (thead + tr there)

var header = ch.createelement("thead");     header.appendchild(ch.createelement("tr")); 

because node.appendchild() returns the appended child...

var appendedchild = element.appendchild(child); 

.. can reference child's parentnode (sample fiddle):

var header = document.createelement("thead")     .appendchild(document.createelement("tr"))     .parentnode; // row's parentnode, i.e.: thead 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -