Skip to content Skip to sidebar Skip to footer

Jquery Remove All Child Elements And Leave Text

Whats the best way to remove all child elements from a div but leave any text that is directly inside the div in jquery. I have tried .childre().remove() but this is adding loads o

Solution 1:

Try:

$('#element_id').children().remove().end().text($.trim($('#element_id').text()));

The $.trim is supposed to remove the surrounding whitespace from the text.


Post a Comment for "Jquery Remove All Child Elements And Leave Text"