i have this code
$.getJSON('check.php', function(data) {
$.each(data, function(key, val) {
$("#badge").append("<tr><td>"+val+"</td></tr><tr><td>-------------------------------------------------------</td></tr>");
});
});
$("td").mouseover(function () {
$(this).css("color","red");
});
my problem is when i hover my mouse cursor on each element they will not change color as what i expected… can someone explain me why??? and help me how to do the right thing.
The event
mouseoverwill not fire as the element is not present on page on load … so you need to do this :The
on()functions will be triggered on thebadgeelement (which is a table im guessing) and will only trigger when the event target is atdand the event ismouseover.One thing to note though – this could easily be done with css :
Thanks @WTK :
Keep in mind, that
on()is available starting jQuery 1.7. For older versions of jQuery and similar outcome use eitherbind(),delegate()orlive().