There are many answers, each of which concerns several points - I hope this can give you an answer, with a good explanation of what and how to use it.
Using click() is an alias of bind('click' ...) . Using bind() accepts the DOM in the same way as when the event listener is configured and binds the function to each of the corresponding elements in the DOM. That is, if you use $('a').click(...) , you will bind the function provided to the click event of each anchor tag in the DOM found when this code was run.
Using live() was an old way in jQuery; it was used to bind events, as bind() does, but it doesnβt just bind them to elements in the DOM when the code runs β it also listens for changes in the DOM and binds events to any future-matched elements like Well. This is useful if you are manipulating the DOM, and you want some event to exist on some elements that can be deleted / updated / added to the DOM later, but do not exist when the DOM is first loaded.
The reason live() now depreciating is because it is poorly implemented. To use live() , you must first select at least one element in the DOM (I suppose). It also led to the fact that a copy of the function is launched to bind to each element - and if you have 1000 elements, then many copied functions.
The creation of the on() function was to overcome these problems. It allows you to bind one event listener to an object that will not be changed in the DOM (therefore, you cannot use on() for an element that will be deleted / added to the DOM later - bind it to the parent object), and simply apply the "filter" element so that the function runs only when it is bubbled up to the element corresponding to the selector. This means that you only have one function that exists (and not a bunch of copies) tied to a single element - a much better approach to adding live events to the DOM.
... and here's what the differences are and why every function exists and why live() depreciating.
Eli Sand Apr 10 2018-12-12T00: 00Z
source share