I need to remove break from a specific div
, i know how to remove all breaks with
$('br').remove();
But I need to keep some breaks elsewhere on the page ,
How would I remove the breaks from a div
with the id "grape1" and "grape12" but leave all others intact?
$('#grape1,#grape12').find('br').remove();
$('br', '#grape1, #grape12').remove();
The second argument in the $
selector allows you to filter your search to a given subset, instead of the entire DOM. In this case we tell jQuery to only look inside the grape1
and grape12
divs. This will match all br's in those div's.
JsFiddle
If that doesn't work (as happened in my case also) it's probably because the <br>
are generated by some scripts after the JS .remove()
code execution.
To check if I was right I set a quite long timeout and all my unwanted <br>
disappeared after that time.
So, in the end I just decided to put a simple CSS
#grape1 br, #grape12 br {
display: none;
}
and eveybody's happy =)
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