JQuery: exclude element

I have the following code:

$(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; }); }); }); 

This code makes all rel on the pages work with the jquery plugin. The problem is that I have a specific div with some id that contains content with rel that should be excluded from this function.

+6
source share
3 answers

You can use not() to exclude elements:

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

You can use :not() in your selector.

For example: $("a[rel]:not(div#divId a[rel])")

A jsfiddle illustrating the use of the :not selector in your case: http://jsfiddle.net/6s6Mm/

+5
source

You can exclude specific elements using the .not () function as follows:

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

Source: https://habr.com/ru/post/889861/


All Articles