Remove from a 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 save some breaks elsewhere on the page,

How to remove div breaks with identifiers "grape1" and "grape12", but leave the rest intact?

+7
source share
3 answers
 $('#grape1,#grape12').find('br').remove(); 
+14
source
 $('br', '#grape1, #grape12').remove();โ€‹ 

The second argument to the $ selector allows you to filter your search for a given subset, not for the entire DOM. In this case, we tell jQuery to only look at grape1 and grape12 . This will match all brs in these divs.

Jsfiddle

+8
source

If this does not work (as it happened in my case), it is possible because <br> generated by some scripts after the JS .remove() code is executed.

To check if I was right, I set a rather long timeout and all my unwanted ones disappeared after that time. So in the end I just decided to put plain CSS

#grape1 br, #grape12 br { display: none; }

and eveybody happy =)

+1
source

All Articles