开发者

jquery remove all child elements and leave text

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜