开发者

jquery remove all child elements and leave text

开发者 https://www.devze.com 2023-01-10 17:31 出处:网络
Whats the best way to remove all child elements from a div but lea开发者_StackOverflowve any text that is directly inside the div in jquery.

Whats the best way to remove all child elements from a div but lea开发者_StackOverflowve any text that is directly inside the div in jquery.

I have tried .childre().remove() but this is adding loads of whitespace in firefox and opera. Works fine in ie though.


Try:

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号