Reputation: 601
I have some html that i need to try and tidy up. Sometimes the text contains contains paragraph tags that contain only a single break tag inside of them. This html isn't needed and I want to delete these paragraphs and their child break tags from specific selectors in my html.
I had understood that the following may work
$(".selectedClass p>br").remove();
But it seems to delete breaks from paragraphs containing breaks among other things.
It's vital my removal only occurs when the html is exactly <p><br/></p>
If the paragraph contains other html/text then its valid and should stay.
Thanks for any help
Upvotes: 0
Views: 115
Reputation: 208002
How about:
$('p').each(function () {
if ($.trim($(this).html()) === '<br>') $(this).remove();
});
Upvotes: 3