10
4

3 回答 3

21
$('#grape1,#grape12').find('br').remove();
于 2012-06-28T03:54:28.777 回答
9
$('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

于 2012-06-28T03:55:39.603 回答
1

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

于 2017-02-08T17:27:31.967 回答