I have multiple <div class='drop'> with jQuery .slideUp() and .slideDown() attached to them. I would like to use some kind of loop to determine which one of the trigger <span class='more'> was clicked and .slideDown() the corresponding <div>. Here's what I've got so far:
$(document).ready(function(){
var i=0;
$('.more').eq(i).click(function(){
$('.drop').eq(i).slideDown(800) && $('.more').eq(i).hide(300);
});
$(".less").eq(i).click(function(){
$(".drop").eq(i).slideUp(800) && $(".more").eq(i).show(500);
});
});
It works as long as I define i and don't put it in a loop. As soon as it's looped like so:
$(document).ready(function(){
for(var i=0; i<$('.drop').length; i++){
$('.more').eq(i).click(function(){
$('.drop').eq(i).slideDown(800) && $('.more').eq(i).hide(300);
});
$(".less").eq(i).click(function(){
$(".drop").eq(i).slideUp(800) && $(".more").eq(i).show(500);};
});
};
});
It stops working. What am I missing?