hothousegraphix
01-21-2009, 03:22 AM
I'm trying to loop through my doc and alter the display of 5 containers on hover.
I can run my hover functions with no problem
$(document).ready(function() {
myDivs = '5';
$('li').hover(
function() {
$('#div_1').addClass("hover");
alert(myDivs);
},
function() {
$('#div_1').removeClass("hover");
}
);
});
I can establish my for loop with no problem
$(document).ready(function() {
myDivs = '5';
for(z=1;z<=myDivs;z++){
alert(z);
};
});
But when I attempt to combine - I get some odd behavior - I'm sure it's my syntax but I'm not sure exactly what it is.
$(document).ready(function() {
myDivs = '5';
for(z=1;z<=myDivs;z++){
alert('#div_'+ z); // here z increments
$('li').hover(
function() {
$('#div_'+ z).addClass("hover");
alert('#div_'+ z); // here z equal to 6 all the time ???
},
function() {
$('#div_'+ z).removeClass("hover");
}
);
}
});
any advice would be much appreciated.
Thanks
I can run my hover functions with no problem
$(document).ready(function() {
myDivs = '5';
$('li').hover(
function() {
$('#div_1').addClass("hover");
alert(myDivs);
},
function() {
$('#div_1').removeClass("hover");
}
);
});
I can establish my for loop with no problem
$(document).ready(function() {
myDivs = '5';
for(z=1;z<=myDivs;z++){
alert(z);
};
});
But when I attempt to combine - I get some odd behavior - I'm sure it's my syntax but I'm not sure exactly what it is.
$(document).ready(function() {
myDivs = '5';
for(z=1;z<=myDivs;z++){
alert('#div_'+ z); // here z increments
$('li').hover(
function() {
$('#div_'+ z).addClass("hover");
alert('#div_'+ z); // here z equal to 6 all the time ???
},
function() {
$('#div_'+ z).removeClass("hover");
}
);
}
});
any advice would be much appreciated.
Thanks