2011-06-06 107 views
6

我有下面的代码:jQuery的:排除元素

$(document).ready(function() 
{ 
    $('a[rel]').each(function() 
    { 
     $(this).qtip(
     { 
     content: { 
      text: '<img class="middle" src="i/icon_processing.gif" alt="l">Loading...', 
      ajax: { 
       url: $(this).attr('rel') 
      }, 
      title: { 
       text: $(this).text(), 
       button: true 
      } 
     } 
    }) 
     .click(function() { return false; }); 
    }); 
}); 

该代码使得网页上的所有相对与醉意jQuery插件工作。 问题是,我有一个特定的div与某些id,该内容与rel需要从此功能中排除。

回答

9

你可以使用not()排除元素:

$('a[rel]').not('#IdOfElement').each(function() 
+2

这只会消除“IdOfElement”的ID的标签,而不是标签内的DIV与该ID。 – 2011-06-06 11:17:58

2

您可以排除特定的元素,像这样的。不是()函数:

$('a[rel]').not('#sepcialElement').each(...); 
+1

这只会消除ID为“IdOfElement”的A标签,而不是具有该ID的D标签内。 – 2011-06-06 11:18:15

5

您可以在选择使用:not()

例如:$("a[rel]:not(div#divId a[rel])")

一个的jsfiddle说明你的情况下,使用:not选择的:http://jsfiddle.net/6s6Mm/

+0

+1有趣的是,不知道你可以在选择器中使用':not' – Andomar 2011-06-06 12:07:35

+0

它会影响性能吗?看起来像更多的文本解析这种方式。 – 2013-09-07 05:37:05