javascript - Complex jQuery if statements including operators -
i show different div depending on class 3 span elems contain. if span hasclass up or up1 code show div class allup . if hasclass up up1 , down show div class twoup.
i wrote following, of course doesn't work.
var $line1 = $(".line1") var $line2 = $(".line2") var $line3 = $(".line3") if($line1.hasclass("up") || $line1.hasclass("up1") && $line2.hasclass("up") || $line2.hasclass("up1") && $line3.hasclass("up") || $line3.hasclass("up1")) { $(".allup").show(); } else if ($line1.hasclass("up") || $line1.hasclass("up1") && $line2.hasclass("up") || $line2.hasclass("up1") && $line3.hasclass("down") || $line3.hasclass("down1")) { $(".twoup").show(); } else if ($line1.hasclass("up") || $line1.hasclass("up1") && $line2.hasclass("down") || $line2.hasclass("down1") && $line3.hasclass("down") || $line3.hasclass("down1")) { $(".oneup").show(); } else { $(".down").show(); }
think i've fixed syntax errors
this should work, , tidies logic quite lot. i've updated class-names lines 1, 2 , 3.
var $lines = $('.line1, .line2, .line3'), numup = $lines.filter('.up, .up1').length, classes = [ 'alldown', 'oneup', 'twoup', 'allup' ]; $( '.' + classes[numup] ).show();
Comments
Post a Comment