0

我需要动态删除一个 H3 元素(这意味着当页面开始加载 DOM 时)。所以 H3 是一个带有 ID="category_rss_widgets" 的 DIV,H3 看起来像:

<h3 class="widget-title"></h3>

我认为做这样的事情:

$(document).ready(function(){
  $('#category_rss_widgets').remove('widget-title');
});

这段代码对吗?我没有测试它,所以我由负责人 Cheers 制作,并在此先感谢

4

3 回答 3

1

Why didn't you just try it out?

Having said that, your code won't work as is. Don't pass a selector to .remove(), because that filters the set of matched elements, it doesn't search for descendants of the matched elements. Instead you can do this:

$(document).ready(function(){
  $('#category_rss_widgets h3.widget-title').remove();
});

The selector '#category_rss_widgets h3.widget-title' will match any h3 elements with the "widget-title" class that are descendants of #category_rss_widgets. Note that to match on a class name you need a . before the class name.

于 2012-09-06T01:07:36.190 回答
1
$('#category_rss_widgets').find('.widget-title').remove();
于 2012-09-06T01:04:47.620 回答
0

尝试这个

$(document).ready(function(){
  $('.widget-title').remove();
});

您正在将选择器传递给 .remove() 方法,该方法将过滤匹配的元素。

于 2012-09-06T01:44:28.723 回答