0

I'm working on a project in PHP and a little bit of JQuery. Im trying to get patients from a database, present them as a table, and then as you hover over on of the rows of the table, it will pop up with a new window showing the patient's health record. Something like that:

enter image description here

I give every row in the table an id dynamically since I dont know how many rows I am going to have, like that:

echo "<tr id=\"patient" .$count. "\" class=\"trying\">

and I increment i by one in every iteration. However, when I try to use the JQuery, I'm having a problem with accessing each id. I tried to do this:

    var count = div.textContent;
    for(var i=0;i<count;i++){
//alert(i);
 $("#patient"+i).mouseover(function() {
     $("#des" +i).show();
 }).mouseout(function() {
     $("#des" +i).hide();
 });
}

But even though the loop does run, it just doesn't work (Im guessing because of scope issues). Any ideas or recommendation on what I can do to solve this problem? Thanks a lot

baki1995
  • 83
  • 2
  • 9
  • You need to bind event by class `trying` – u_mulder Nov 14 '16 at 20:13
  • Define "doesn't work". What *does* it do? When you debug, how does it fail? Why are you "guessing because of scope issues"? What indication do you have for that? Why are you binding so many mouseover events in the first place? Why not just do it once for a selector which targets all of the elements you want to target? – David Nov 14 '16 at 20:13
  • infamous for loop – epascarello Nov 14 '16 at 20:14
  • count? dont they have their own id they can use? –  Nov 14 '16 at 20:14

0 Answers0