3

Recently was working with image maps and trying to do something on hover of an image map. Naturally I tried .hover() first, but that didn't work and so when I tried .mouseover() that worked.

My question is, why does one work and not the other?

/*This function works*/
$(document).on('mouseover', '#some-map', function(){
    console.log('I am hovering with mouseover()');
}).on('mouseout', function(){
    console.log('I am no longer hovering with mouseover()');
});

/*This function does not work*/
$(document).on('hover', '#some-map', function(){
    console.log('This is from hover()');
}, function(){
    consoel.log('Out from hover()');
});
Adjit
  • 10,134
  • 12
  • 53
  • 98

1 Answers1

1

there ar no on('hover' ... method in jquery you can write it like this

$('#some-map').hover(function(){
   alert('This is from hover()');
}, function(){
   alert('Out from hover()');
});
kaxi1993
  • 4,535
  • 4
  • 29
  • 47
  • Ahh, okay. That makes sense then. So how would I create a hover event for a dynamically created element? – Adjit Nov 06 '14 at 17:08
  • i always used to write like this: – kaxi1993 Nov 06 '14 at 17:52