Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude a class from function

Tags:

jquery

Basically I'm making a filter for my portfolio so that you can click on "Web Design," for example, and it will fadeOut the divs that aren't marked as such. The problem is I have some title divs houses within "#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 do that line #content div . each(function) that will exclude things with the class "title." I think it should be as simple as an if statement, but I must be doing something wrong, and I'm very new to jQuery so I'm not sure what this syntax should be. Thanks.

like image 837
prismspecs Avatar asked Dec 09 '22 00:12

prismspecs


2 Answers

Try using .not like below,

$('#content div').not('.title').each(function() {
like image 54
Selvakumar Arumugam Avatar answered Dec 15 '22 00:12

Selvakumar Arumugam


You can exclude it immediately with the :not selector:

$('#content div:not(.title)')
like image 33
Sampson Avatar answered Dec 14 '22 23:12

Sampson