I need to append an element onclick just after another (a textarea).
How do I do that?
The Element. after() method inserts a set of Node or string objects in the children list of the Element 's parent, just after the Element . String objects are inserted as equivalent Text nodes.
To insert element as a first child using jQuery, use the prepend() method. The prepend( content ) method prepends content to the inside of every matched element.
The accepted answer will work in this specific case, but to insert an element after another more generally, the following does the job:
someElement.parentNode.insertBefore(newElement, someElement.nextSibling);
Where newElement is the element to be inserted and someElement is the element it is to be inserted after.
W3C insertBefore method of the Node interface
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With