Exclude class from function

Basically I create a filter for my portfolio so that you can click "Web Design", for example, and it will be fadeOut divs that are not marked as such. The problem is that I have some title divs at home inside "#content" that I don't want to touch.

$(document).ready(function() { $('#filternav a').click(function() { $('#filternav .current').removeClass('current'); $(this).parent().addClass('current'); var filterVal = $(this).text().toLowerCase().replace(' ','-'); if(filterVal == 'view-all') { $('#content div.hidden').fadeIn('slow').removeClass('hidden'); } else { $('#content div').each(function() { if(!$(this).hasClass(filterVal)) { $(this).fadeOut('normal').addClass('hidden'); } else { $(this).fadeIn('slow').removeClass('hidden'); } }); } return false; }); }); 

I want to add something to the line of the #content div. each (function) that excludes things with the "title" class. I think it should be as simple as an if statement, but I have to do something wrong, and I'm very new to jQuery, so I'm not sure what this syntax should do. Thanks.

+4
source share
3 answers

Try using .not as shown below.

 $('#content div').not('.title').each(function() { 
+6
source

You can immediately exclude it with : not selector :

 $('#content div:not(.title)') 
+4
source

Use . not () selector .

Replace

 $('#content div') 

FROM

 $('#content div').not(".title") 
+3
source

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


All Articles