I have several containers on my page that have a trailing <br> I want to remove. The containers are in the same class, but I am having trouble with the ":last" selector (if that is what I should be using).
Here is my HTML:
<div class="side-section">
<p>Something 1</p>
<br>
</div>
<div class="side-section">
<p>Something 2</p>
<br>
</div>
<div class="side-section">
<p>Something 3 <br> Test 3</p>
<br>
</div>
How do I remove the last <br> from .side-section containers? I tried the below but it did not work:
$(".side-section br").filter(":last").remove();
$(".side-section").filter("br:last").remove();
$(".side-section > br:last-child").remove();
the >
selector is there to make sure you dont remove <br>
tags inside the <p>
tag
This should do the trick:
$(".side-section > br:last-child").remove();
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