I was having problems with an
$('.myElement').on('hover',function({...});
After trying .on('hover'
, .hover()
, which both didn't work, I tried .live('hover',)
.
.live('hover',)
worked.. however, I'm using jQuery 1.8.3 so why is this?
Here's the code I was working with:
jQuery
$('.myElement > a').live('hover',function(event) {
//do stuff
}
HTML
<div class="myElement">
<a href="#" />
</div>
Sometimes I wonder if I'm just making dumb mistakes or the languances are just crazy..
on()
only works like live()
when you pass it a delegated selector in the second parameter. In your case the primary selector would be the container element which your .myElement
elements are being appended to and the delegate would be .myElement
, like this:
$('.parentOfMyElement').on('hover', '.myElement', function() {
// do stuff...
});