I would like to have both a hover and remove hover event. The nodes which have this event are added dynamically, so I wish to use on(). When adding a hover event, it works great (the #second list below). For some reason when I add the off hover event, not even the add hover event will work (#first list below).
Please provide any clues. A live example is located at http://jsfiddle.net/NV7hR/
Thanks
$(document).ready(function() {
$("#first").on("hover", "a", function(event) {
$(this).parent().css("background-color", "yellow");
}, function(event) {
$(this).parent().css("background-color", "");
});
$("#second").on("hover", "a", function(event) {
$(this).parent().css("background-color", "yellow");
});
});
<body>
<ul id="first">
<li><a href="#"/>Link</a></li>
<li><a href="#"/>Link</a></li>
<li><a href="#"/>Link</a></li>
</ul>
<ul id="second">
<li><a href="#"/>Link</a></li>
<li><a href="#"/>Link</a></li>
<li><a href="#"/>Link</a></li>
</ul>
</body>
Split the hover into mouseenter and mouseleave, which is what hover is shorthand for anyways.