2010-09-15 59 views
2

嗨,我想删除以下JQuery的选择删除所有class!= “dgItem”

<tr><td style="padding-left:20px;" class="content"> 

这正常工作与

$(".content").first().remove(); 

但在一些我的网页我有这个

<tr class="dgItem"><td class="content"> 

它被移除。 是否有可能让JQuery只选择第一个例子?

回答

6

试试这个:

例子:http://jsfiddle.net/7c7kD/

$('tr:not(.dgItem) > td.content').remove(); 

使用jQuery's :not() selector,这将删除td.content元素是<tr>不具有类.dgItem的直接孩子。

+0

您的描述有些偏离,但答案是正确的......它删除了'tr'的直接子代的'td.content'元素,它是** not **'.dgItem'。 +1 – gnarf 2010-09-15 13:51:28

+0

@gnarf - 非常真实。感谢您的领导! :o) – user113716 2010-09-15 13:53:09

+0

非常感谢:-) – gulbaek 2010-09-15 13:55:11

1

为什么不在第一类表格列class="content anotherclassname"上添加第二个类名?然后请拨打电话$(".anotherclassname").remove();

+0

不能直接访问源代码:-( – gulbaek 2010-09-15 13:54:10