1

I am building a site using Bootstrap 3.2.0. Because jQuery is fully supported I am using quite a lot of its code, however I seem to be unable to use .on(). The function does not seem to work, however, if instead I use older .delegate() everything works great.

Yes I am making syntax change appropriately when I try .on() vs .delegate().

This works:

$(document).delegate('.myEm', 'mouseover', function() {
    ...
});

and this doesn't:

$('.myEm').on('mouseover', function() {
    ...
});

I'm just wondering if this is something unique to my setup or someone else experienced this?

Thanks.

Mike Causer
  • 8,196
  • 2
  • 43
  • 63
santa
  • 12,234
  • 49
  • 155
  • 255

1 Answers1

1

To use event delegation with .on:

$(document).on('mouseover','.myEm',function() {
Blazemonger
  • 90,923
  • 26
  • 142
  • 180
  • OK, totally my bad. My jQuery version was ancient. Just changed to 2.1.1 and we're back in business. Also the syntax had it a bit backwards. – santa Sep 23 '14 at 13:22
  • No, [1.11 is a current version of jQuery](http://blog.jquery.com/2014/05/01/jquery-1-11-1-and-2-1-1-released/). The 1.x versions are compatible with IE 6/7/8, while the 2.x versions strip out that compabibility for a smaller download. – Blazemonger Sep 23 '14 at 13:38
  • Hah... good to know. But for some reason 1.11 did not work with .on() and I was testing on the latest FF. – santa Sep 23 '14 at 16:55