jQuery: Multiple selector issue -



jQuery: Multiple selector issue -

i having problems showing divs div has 3 selectors need match on. these typical:

<div class="pinfo draft sept-2010">...</div> <div class="pinfo published feb-2011">...</div> etc...

there pinfo followed review state (published or draft) , time frame (month + year)

this have:

// hide rows $(".pinfo").hide(); // now, show rows selectors in filters built (idx in $cls) { console.log('filter: '+$cls[idx]); $('.pinfo').filter($cls[idx]).show(); }

where $cls array of strings. strings class selectors built given choices made user input form. example:

$cls = [".draft .sept-2011", ".published .sept-2011"]

i having problems showing divs div has 3 selectors need match on.

any help appreciated.

thanks! eric

don't utilize for..in loop on an array. utilize them on objects, , hasownproperty. can utilize jquery's $.each here loop through array. the big problem. selector ".draft .sept-2011" says "find elements class sept-2011 have ancestor element class draft. can combine multiple class selectors: want .draft.sept-2011.

so code might this:

$cls = [".draft.sept-2011", ".published.sept-2011"] var $pinfo = $('.pinfo').hide(); $.each($cls, function(idx, val) { $pinfo.filter(val).show(); });

note i've cached $('.pinfo') selector phone call sake of performance.

jquery

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -