JavaScript move node to position after lastChild -
I have a system script that takes elements up or down visually (like li elements And tr ) However, when the element is already already, I need to see it below instead. I tried using the correct code references to appendChild and received an error because the element I'm running is already a child of her parents << P>
There is no framework
Then we can say that we have found the basic element s_parent , we want to move the element of the child s_move And the four characters are tr element s_parent , how do we s_move after s_parent.lastChild ?
var s_parent = document.getElementsByTagName ('table') [0]; Var s_move = t.getElementsByTagName ('tr') [0]; Use the Node.appendChild method on the parent node:
/ P>
s_parent.appendChild (s_move);
which will add your element after the last child of the original element.
Good to know:
When the DOM elements are manipulated with vanilla js, by hand indentation in the templateting system or in your HTML markup Be aware of possible text nodes created
Compressed markup: & lt; Ul & gt; & Lt; Li & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; / Li & gt; & Lt; / Ul & gt;
-
ul firstli - first
li.nextSiblingsecondli
but indent markup: & lt; Ul & gt; & Lt; Li & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; / Li & gt;
-
ul.firstChildis#textNode - the first
li. NextSiblingis#textNode
Check:
- < / Ul>
Comments
Post a Comment