jQuery attribute selector inside a jQuery object

Posted by chifliiiii on Stack Overflow See other posts from Stack Overflow or by chifliiiii
Published on 2012-06-27T15:12:09Z Indexed on 2012/06/27 15:15 UTC
Read the original article Hit count: 787

Im trying to set up a quicksand with multiple filters and the approach im taking in the following which im not sure if its the best.

$filteredItems = $containerClone.find('.portfolio-item-marketing').filter(function(index){

        if ( $filterA != 'all' && $filterB != 'all' )
        {
            return jQuery(this).find('.portfolio-item-marketing[data-type~=' + $filterA + ']') || jQuery(this).find('.portfolio-item-marketing[data-type~=' + $filterB + ']');
        }

        if ( $filterA != 'all' && $filterB == 'all' )
        {
            return jQuery(this+'[data-type~='+$filterA+']')  ;
        }

        if ( $filterA == 'all' && $filterB != 'all' )
        {
            return  jQuery(this).find('.portfolio-item-marketing[data-type~=' + $filterB + ']');
        }

        if ( $filterA == 'all' && $filterB == 'all' )
        {
            return jQuery(this).find('.portfolio-item-marketing');
        }

    });

As you see in the code i tried 2 different methods ( First "if" and second "if" ). Im not sure if i can use find inside a filter but i also dont know how to get the attribute from the jQuery object.

I can not use

jQuery(this).attr('data-type') == $filterA

Because the attribute maybe contain various filters .Thats why im trying to use jQuery "~="

Should i give up and end using a indexOf ?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-selectors