Skip to content Skip to sidebar Skip to footer

Jquery: Remove A Closing Tag

Is there a way to use jQuery to remove a single closing HTML-Tag? Example:
CONTENT
I h

Solution 1:

No, that is not possible. There simply are not closing tags at all in the page.

The closing tags exists in the HTML code before it's parsed, once it's parsed each element is one object, not a start and end point in the markup.

The browser will have tried to fix the invalid markup, but the problem is that different browsers will have done different things. Some browsers may ignore the extra closing tag, while others may imply a starting tag to make it a complete element. You could try to rearrange the elements to have them restored to the state they would have been without the extra closing tag, but to do that you need to know what all different browsers will have done when parsing the code.

Even worse, if that code is inside another div, it would be that tag that ended there, and the invalid code would come after that. How that would be handled depends on what the code is outside the code that you have shown, and also there different browsers may handle the invalid code in different ways.

Solution 2:

Clone metod:

$tmp = $('.one').clone( true );
$('#wrapper').empty().append($tmp)

Post a Comment for "Jquery: Remove A Closing Tag"