I use a for loop to show all elements via jQuery in this one function:
<script>
$(function() {
var number_menus = 9;
for (i = 1; i <= number_menus; i++) {
var p1 = +i;
$(".wm_" + i).show()
.css("background-image", "url(imagenes/footer/m/" + i + ".png)");
$(".wm_" + i).mouseover(function() {
$(this).css(
"background-image",
"url(imagenes/footer/m/" + i + "_down.png)"
);
alert("this_down.png");
});
$(".wm_" + i).mouseout(function() {
$(this).css(
"background-image",
"url(imagenes/footer/m/" + i + ".png)"
);
});
}
});
</script>
By other side i have this code for show all elements or images loading and create mouseover effect :
<div id="web_footer_publi">
<div id="web_footer_marks" class="wm_1"></div>
<div id="web_footer_marks" class="wm_2"></div>
<div id="web_footer_marks" class="wm_3"></div>
<div id="web_footer_marks" class="wm_4"></div>
<div id="web_footer_marks" class="wm_5"></div>
<div id="web_footer_marks" class="wm_6"></div>
<div id="web_footer_marks" class="wm_7"></div>
<div id="web_footer_marks" class="wm_8"></div>
<div id="web_footer_marks" class="wm_9"></div>
</div>
When create the function think in show in loop all posibilities for all classes but when i go over images this show me other images of loop and works bad , i want , please , tell me what´s bad in this code for works with it
Thank´s !!
I think this is caused because of context. Create a closure inside the loop so the code executes straight away. There should be other ways to solve this too.