2

Is there any difference between :

$('selector').change(function() {});

and

$('selector').on("change", function() {});

And if there is, which one should I use in most cases?

L. Techer
  • 65
  • 1
  • 9

3 Answers3

2

No difference, internally change function would use .on(...) to bind the respective event.

function (data, fn) {
    return arguments.length > 0 ? this.on(name, null, data, fn) : this.trigger(name);
}

Source

skreborn
  • 2,133
  • 2
  • 16
  • 27
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
1

The is no difference at all, they both trigger the same javascript function. You can use both in any browser that supports the addEventListener modules.

Check the list of browsers that support it: http://caniuse.com/#feat=addeventlistener

However to remove the event, you'll have to use .off( "change" ) as the jquery doc suggests

Hope it helps

RDardelet
  • 564
  • 3
  • 11
1

in accordance to method documentation $('selector').change( function() {}) is just a shortcut for $('selector').on("change", function() {});. indeed this is the same.

A. Wolff
  • 74,033
  • 9
  • 94
  • 155
ashirman
  • 141
  • 1
  • 6