Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: exclude element

I have a 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 make all rel's on pages to work with tipsy jquery plugin. The problem is that i have a specific div with some id, that holds content with rel that needs to be excluded from this function.

like image 654
Milen Mihalev Avatar asked Jun 06 '11 11:06

Milen Mihalev


People also ask

What is not () in jQuery?

The not() is an inbuilt function in jQuery which is just opposite to the filter() method. This function will return all the element which is not matched with the selected element with the particular “id” or “class”. Syntax: $(selector).not(A) The selector is the selected element which is not to be selected.

Is not condition in jQuery?

jQuery not() Method: This method returns elements that do not match a defined condition. This method specifies a condition. Elements that do not match the condition are returned, and those that match will be removed. Mostly this method is used to remove one or more than one elements from a group of selected elements.

How do you say not in jQuery?

jQuery :not() Selector The :not() selector selects all elements except the specified element.


3 Answers

You could use not() to exclude elements:

$('a[rel]').not('#IdOfElement').each(function()
like image 147
Andomar Avatar answered Nov 15 '22 05:11

Andomar


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/

like image 22
Dvir Avatar answered Nov 15 '22 06:11

Dvir


You can exclude specific Elements with the .not() function like this:

$('a[rel]').not('#sepcialElement').each(...);
like image 44
Benjamin Kammerl Avatar answered Nov 15 '22 05:11

Benjamin Kammerl