Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery on vs click methods

Tags:

jquery

I know that the on method, is supposed to replace live, delegate etc. But is there any point in using it on places where you're currently using the click event? For example on elements that are not dynamically generated.

like image 324
Johan Avatar asked Dec 22 '11 09:12

Johan


People also ask

What is the difference between on click and click in jQuery?

on() differs from . click() in that it has the ability to create delegated event handlers by passing a selector parameter, whereas . click() does not.

Is jQuery click deprecated?

click() shorthand is deprecated at jQuery 3 The . on() and . trigger() methods can set an event handler or generate an event for any event type, and should be used instead of the shortcut methods.

What is the difference between .on click function ()) and .click function?

So onclick creates an attribute within the binded HTML tag, using a string which is linked to a function. Whereas . click binds the function itself to the property element.

How use jQuery click method?

To trigger the onclick function in jQuery, click() method is used. For example, on clicking a paragraph on a document, a click event will be triggered by the $(“p”). click() method. The user can attach a function to a click method whenever an event of a click occurs to run the function.


1 Answers

It's not specifically worth replacing click(), as in the jQuery source it converts all the 'shortcut' event handlers (like click(), keyup() etc.) to on("event", fn) anyway.

like image 180
Rory McCrossan Avatar answered Sep 25 '22 17:09

Rory McCrossan