Jump to content

MouseOvers with For Loops - Possible?


chrisprse

Recommended Posts

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:

 

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:

 

$("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

Link to comment
https://forums.phpfreaks.com/topic/158349-mouseovers-with-for-loops-possible/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.