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.
精彩评论