if or statement within jquery $.each values -


is there more efficient way following bit of javascript? i'd love trim down, couldn't think of way it. thanks!

      var sizes = []; //this dynamic array button clicks in above menu include of ['s','m','l','xl']       sizes = ['s','m'] // we'll use example saying s , m buttons active.       $('div').each(function() {         var t = $(this);         var mysizes = t.attr('class').split(/\s+/);         var length = sizes.length;         if(length == 0) {             t.show();         }         if(length == 1) {             if(t.hasclass(sizes[0])) {                 t.show();             } else {                 t.hide();             }         }         if(length == 2) {             if(t.hasclass(sizes[0]) || t.hasclass(sizes[1])) {                 t.show();             } else {                 t.hide();             }         }         if(length == 3) {             if(t.hasclass(sizes[0]) || t.hasclass(sizes[1]) || t.hasclass(sizes[2])) {                 t.show();             } else {                 t.hide();             }         }         if(length == 4) {             if(t.hasclass(sizes[0]) || t.hasclass(sizes[1]) || t.hasclass(sizes[2]) || t.hasclass(sizes[3])) {                 t.show();             } else {                 t.hide();             }         }     }); 

any appreciated.

something

$(document).ready(function(){    var sizes = [];     sizes = ['s','m'];    $("div").hide();    $.each(sizes, function(index, item) {        $("."+item).show();    }); });     

jsfiddle


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -