最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Remove <br> in a specific div class - Stack Overflow

programmeradmin1浏览0评论

I want to remove all <br> tags in the div class category alternate but for some reason I can't get it work.

Here is what I got so far:

$('div.category alternate').find('br').remove();

I want to remove all <br> tags in the div class category alternate but for some reason I can't get it work.

Here is what I got so far:

$('div.category alternate').find('br').remove();
Share Improve this question edited Sep 30, 2012 at 18:05 Felix Kling 818k181 gold badges1.1k silver badges1.2k bronze badges asked Sep 30, 2012 at 17:50 user1685565user1685565 3372 gold badges5 silver badges16 bronze badges 2
  • That should work, your selector is wrong. What's the HTML look like? – sachleen Commented Sep 30, 2012 at 17:52
  • 1 What do you think he means? You have some HTML being sent to the browser, and you want to modify the elements, right? Well, "What does the HTML look like?" – I Hate Lazy Commented Sep 30, 2012 at 18:06
Add a ment  | 

3 Answers 3

Reset to default 6

If your HTML looks like this:

<div class="category alternate">
   whatever<br>
</div>

then you want this:

$('div.category.alternate br').remove();

On the other hand, if your HTML looks like this:

<div class="category">
   <div class="alternate">
     whatever<br>
   </div>
</div>

then you want this:

$('div.category .alternate br').remove();

There is no such thing as an <alternate> tag.

$('div.category alternate') tries to find all alternate tags inside div with class category. Maybe you ment $('div.category .alternate')

发布评论

评论列表(0)

  1. 暂无评论