first let me say i have seen this post.
which says (as does api.jquery.com) that the .live()
and .on()
let you assign a jquery event, which applies even to future elements. however my following jquery:
$("#playerImg").on("mouseenter",function () {
console.log("works");});
works at the start but after i run this code:
function move(moveTo) {
document.getElementById(player.currentLocation).innerHTML = "";
player.currentLocation = moveTo;
document.getElementById(player.currentLocation).innerHTML += player.displayText;
}
here are relevant variables
var player = {
"displayText" : "<img src = 'http://3.bp.blogspot.com/-kAhN0HX-MBk/T_5bApfhbJI/AAAAAAAAAuI/lUww8xT9yV8/s1600/smileys_001_01.png'" +
id='playerImg' "class='onTop' alt='you' border='0' />",
"currentLocation": 0 //(i use a 5 * 5 table with id's 0-24)
}
the above code doesnt run. how can i make an event in jquery, which can run on elements that dont exist yet?