Insert Content Before And After An Element Without Autoclosing Tags
Say I have the following:
content
And I want to insert some stuff before it ** (notice the unclosed div)**: $('#content').before('pr
Solution 1:
You can't insert partial or unclosed tags. Inserting elements in the DOM must insert only whole elements.
Your choices are:
Extract the element you want to be wrapped in your new element, insert the new container object and then put your original element into the container.
Manipulate the HTML of a parent directly (generally not recommended).
Use the jQuery
.wrap()
method which does the option in #1 for you. See here for more info on jQuery's.wrap()
.
Post a Comment for "Insert Content Before And After An Element Without Autoclosing Tags"