user1450749
user1450749

Reputation: 183

remove <br> from specific div

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?

Upvotes: 12

Views: 24002

Answers (3)

Sgaddo
Sgaddo

Reputation: 181

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 =)

Upvotes: 2

Brombomb
Brombomb

Reputation: 7086

$('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

Upvotes: 9

xdazz
xdazz

Reputation: 160893

$('#grape1,#grape12').find('br').remove();

Upvotes: 22

Related Questions