With this code:
<body>
<div id="a1" style="width:200px; height:100px; background-color:black; margin:10px;"></div>
<div id="a2" style="width:200px; height:100px; background-color:black; margin:10px;"></div>
<script>
i = 1;
$("#a" + i).hover(function(){
$("#a" + i).css("background-color", "grey");
}, function(){
$("#a" + i).css("background-color", "black");
});
i = 2;
$("#a" + i).hover(function(){
$("#a" + i).css("background-color", "grey");
}, function(){
$("#a" + i).css("background-color", "black");
});
</script>
</body>
I cannot receive the hover effect for each element, when I over mouse on the first, the second element changed. I think jquery not same as javascript about the sequence of commands, may be the hover for the first still not run yet. I can use queue function to order the command?