Skip to content Skip to sidebar Skip to footer

Jquery / Regex: Remove Div With Nested Divs From Td

I have a TD that always contains a div and some text outside the div. The div has four nested divs that always follow the below structure. The only thing I am interested in is th

Solution 1:

Ten kittens in China just died, and four unicorns where brutally sterilized! Why would you do such a thing with a regex ?

To remove every DOM node and just keep textNodes, filter on nodeType and remove the rest.

$('#myTD').contents().filter(function() {
    returnthis.nodeType != 3;
}).remove();

FIDDLE

Solution 2:

Solution 3:

It's as simple as -

$('#myTD').find('div').remove();

http://api.jquery.com/remove/

Post a Comment for "Jquery / Regex: Remove Div With Nested Divs From Td"