Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery select all images except those with a certain class

I am trying to use lazyload on a page.

The code i have is:

$(function() {
    $("img.lazy").lazyload();
});

However i want it to ignore all images that have the class "notlazy". How do i put a condition in the selector?

Thanks in advance, sorry for this primitive question.

like image 701
Frank Avatar asked Dec 20 '10 00:12

Frank


People also ask

How to exclude selector in jQuery?

To exclude first and second element from jQuery, use the slice() method.

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”. The selector is the selected element which is not to be selected.


1 Answers

Try:

$('img.lazy').not('.notlazy')

There are a few other ways...

$('img.lazy:not(.notlazy)')
$('img.lazy').filter(function() {return !$(this).hasClass('notlazy');});
like image 54
sje397 Avatar answered Oct 05 '22 23:10

sje397