Skip to content Skip to sidebar Skip to footer

Switch Statement And Loops Using Jquery/javascript

Is there a way I can generate switch statements in jquery/javascript by using some sort of loop to do the work for me? For example, if I had a statement like: switch ($('#play op

Solution 1:

for (var i = 1; i <= $("#play option:selected").text(); ++i) {
    $("#play_"+i).slideDown().find("input").addClass("someClass");
}

If you select 10 that loop will find the ten elements from #play_1 to #play_10 and animate them.


Solution 2:

for (var i = 1; i <= parseInt($("#play option:selected").text(), 10); i++) {
    $("#play_" + i).slideDown().find("input").addClass("someClass");
}

Post a Comment for "Switch Statement And Loops Using Jquery/javascript"