GriffLab
GriffLab

Reputation: 2166

Append child at node x?

I know that to remove a child node at a certain position in the DOM tree I can do this;

this.element.removeChild(this.element.childNodes[index]);

I am trying to figure out if there is a way to append child at node x like above but in reverse. In pseudo code it would be something like (I think);

this.element.appendChild(child at node[index]));

Thanks for helping me with this.

Upvotes: 1

Views: 76

Answers (1)

VisioN
VisioN

Reputation: 145408

Maybe you are looking for insertBefore:

this.element.insertBefore(element, this.element.childNodes[index]);

Upvotes: 1

Related Questions