Hi,
Is there a way to remove this
<p> </p>
using jQuery?
Thank you for your help in advance!
Hi,
Is there a way to remove this
<p> </p>
using jQuery?
Thank you for your help in advance!
Try:
$('p')
.filter(function() {
return $.trim($(this).text()) === ''
})
.remove()
What that does is it finds all the <p>
s that have nothing in them, and removes them from the DOM.
give it an id (to get the selector).
<p id="myP"></p>
<script>
$("#myP").remove();
</script>
As Greg mentions above, testing the trimmed .text() will remove paragraphs w/ no text, but do have a self-contained element like the <img>
tag. To avoid, trim the .html() return. As text is considered a child element in the DOM, you'll be set.
$("p").filter( function() {
return $.trim($(this).html()) == '';
}).remove()