MouseOvers with For Loops - Possible?
Hello
I pass a variable to JavaScript from PHP. Currently this variable is 38. It will increase every time new records are stored in the database.
This doesn't work:
-
$(document).ready(function() {
for(i = 1; i <= num_rows; i++) {
$("a#link-" + i).mouseover(function() {
$("#tip-" + i).show();
})
$("a#link-" + i).mouseout(function() {
$("#tip-" + i).hide();
})
}
});
Whereas this does:
-
$(document).ready(function() {
$("a#link-1").mouseover(function() {
$("#tip-1").show();
$("a#link-1").mouseout(function() {
$("#tip-1").hide();
$("a#link-2").mouseover(function() {
$("#tip-2").show();
$("a#link-2").mouseout(function() {
$("#tip-2").hide();
.
.
.
$("a#link-38").mouseover(function() {
$("#tip-38").show();
$("a#link-38").mouseout(function() {
$("#tip-38").hide();
});
Obviously I don't want to edit this file everytime I have a new record in the database!
Does anyone have any ideas?
Regards
Chris