javascript - jQuery filter for each string that's not null -


how apply jquery filter every string that's not null?

basically, have following code , want make work number of "selectors" being set beforehand.

the list of selectors available in array.

if (typeselector === '' && colorselector === '') {             $('.product').filter(selector).show(); } else if (typeselector === '') {   $('.product').filter(selector).filter(colorselector).show(); } else if (colorselector === '') {   $('.product').filter(selector).filter(typeselector).show(); } else {   $('.product').filter(selector).filter(typeselector).filter(colorselector).show(); } 

thanks suggestions/help!

to simplify can use chaining:

var products = $('.product').filter(selector); if (typeselector !== '') {             products = products.filter(typeselector); } if (colorselector !== '') {             products = products.filter(colorselector); } products.show(); 

or this:

var products = $('.product').filter(selector); var selectors = [typeselector, colorselector];  selectors.each(function(selector) {     if (selector !== '') {         products = products.filter(selector);     } }); products.show(); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -