I have a code generated by PHP which has unwanted br tags.
How can I remove the <br> when appears immediately after opening <ul> ie: it is not inside <li>
How can I remove <br> when it is immediately after closing tag of </ul>
<ul>
<br>
<li> ....</li>
<li> ....</li>
<li> ....</li>
</ul>
<br>
Seeing as the only legal child of a <ul> is an <li> tag:
$('ul').children(':not(li)').remove();
or if you want to be more specific and only address this specific error:
$('ul > br').remove();
To remove a <br> that follows a <ul>, you can use the "preceding" CSS selector:
$('ul + br').remove();
Note that the latter does not refer just to the "opening" <ul> tag, but the entire <ul> element up to and including its closing </ul> tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With