Friday, May 13, 2022

[FIXED] How can I implement prepend and append with regular JavaScript?

Issue

How can I implement prepend and append with regular JavaScript without using jQuery?


Solution

Perhaps you're asking about the DOM methods appendChild and insertBefore.

parentNode.insertBefore(newChild, refChild)

Inserts the node newChild as a child of parentNode before the existing child node refChild. (Returns newChild.)

If refChild is null, newChild is added at the end of the list of children. Equivalently, and more readably, use parentNode.appendChild(newChild).



Answered By - Grumdrig
Answer Checked By - Terry (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.