0

Possible Duplicate:
jquery on vs click methods

I have noticed some are saying to use "on" in the latest jQuery, but what is the difference and is it true I should use it?

$("#dataTable td").on("click", function(event){
    alert($(this).text());
});

$("#dataTable td").click(function(event){
    alert($(this).text());
});
Community
  • 1
  • 1
TruMan1
  • 33,665
  • 59
  • 184
  • 335

1 Answers1

1

None. Look here in the jQuery source. The .click() function is basically just an alias for .on('click'), the relevant code being this:

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

Although .click() is more concise I would recommend using .on if you want to be consistent, as it always was intended to unify event handling introduced with .bind, .live and the shorthand methods like .click.

Daff
  • 43,734
  • 9
  • 106
  • 120