To append an element outside of another element using jQuery, you can use the .insertAfter()
method in combination with the .parent()
method.
For example, if you have an HTML structure like this:
65 chars4 lines
And you want to append a new element after the parent element, you can use this code:
64 chars2 lines
This code creates a new <div>
element with the text "New Element", and then uses the .insertAfter()
method to insert it after the parent element's parent (i.e. outside the parent element).
Alternatively, you can also use the .after()
method to achieve the same result:
55 chars2 lines
This code uses the .after()
method to insert a new <div>
element with the text "New Element" after the parent element's parent.
gistlibby LogSnag