Jquery:排除元素

我有以下代码:

$(document).ready(function() { $('a[rel]').each(function() { $(this).qtip( { content: { text: 'lLoading...', ajax: { url: $(this).attr('rel') }, title: { text: $(this).text(), button: true } } }) .click(function() { return false; }); }); }); 

此代码使页面上的所有rel都与tipy jquery插件一起使用。 问题是我有一个带有一些id的特定div,它包含需要从此函数中排除的rel内容。

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

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

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

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

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

您可以使用.not()函数排除特定元素,如下所示:

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