These doubts are usually about what the real difference between them is and when to use them. This method has been used for the longest time. In the meantime, it has solved various cross browser problems. When it is used to connect event handlers, it is still very simple, but there are also some performance problems, which will be listed below. This is not a good way. In this way, it not only implicitly iterates additional event handlers among all matching elements, but also these operations are wasteful redundant , because these same event handlers are added to all matching tags over and over again.
You call. But beneath the surface,. More Update Now. Improve this question. Community Bot 1 1 1 silver badge. I Like PHP, sometimes people vote things down if they don't feel it's a question that couldn't be answered by a manual or appears to be a homework question.
Typeoneerror--Thanks for support, i already read the manual and when i didn't understand the clear difference then i post here. I agree a wiki-ish entry of something like this would be very helpful, I see confusion around this, especially with. Nick Craver Thanks for editing, actually i m bad in english lol. As for your edit,. I'll add a description to my answer below. Show 1 more comment. Active Oldest Votes. Triggering - for the updated question There are 2 main event-handler triggering functions available, they fall under the same "Event Handler Attachment" category in the API , these are.
Improve this answer. Nick Craver Nick Craver k gold badges silver badges bronze badges. Very thorough. One small correction: trigger does not fire a native event. Crescent - Updated to be less ambiguous, I meant that it fires the native event actions , like forms submission, link following etc Nick from what I'm reading, it seems like your take on live is different from the one you gave me here: stackoverflow.
The weight cost vs. If you're page structure isn't that big you you don't have that many events then you're fine The first two are equivalent.
Or maybe mouse moved. Fyodor Soikin Fyodor Soikin To be accurate,. It was more convenient to explain it this way. Add a comment. Load Comments. What's New. Most popular in HTML. How to auto-resize an image to fit a div container using CSS? How to fix the height of rows in the table? Most visited in JQuery. JQuery Set the value of an input text field How to change the background color after clicking the button in JavaScript?
The selection that is made is basically thrown away since it is only used to register the event handler on the document. Using event. Your events always delegate all the way up to the document.
This can affect performance if your DOM is deep. Using the Delegate Method The. If you skipped over the explanation of the. The selection isn't actually performed up front, but is only used to register onto the root element.
Chaining is supported correctly. Since this technique uses event delegation, it can work with dynamically added elements to the DOM where the selectors match. As long as you delegate against the document you can also wire-up event handlers before the document ready event.
Cons Changing from a. However, the metadata stored at the root element should be considerably smaller compared to using the. Using the On Method Did you know that the jQuery. Pros Brings uniformity to the various event binding methods. Simplifies the jQuery code base and removes one level of redirection since the. Still provides all the goodness of the. Cons Brings confusion because the behavior changes based on how you call the method.
Conclusion tl;dr If you have been confused about the various different types of event binding methods then don't worry, there has been a lot of history and evolvement in the API over time.
0コメント