2011-06-06 52 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