I was thinking about performance regarding
.click()
vs .live("click")
and that left me wondering about how .live does work.
Does it monitor DOM changes and when it detects a change in the DOM it just attaches the event then, does it use some sort of timer (I wouldn't think so, but if it did this is very important, timers make me a sad person)
In short: . bind() will only apply to the items you currently have selected in your jQuery object. . live() will apply to all current matching elements, as well as any you might add in the future.
on is a more streamline way of attaching events. Use of the . live() method is no longer recommended since later versions of jQuery offer better methods that do not have its drawbacks. In particular, the following issues arise with the use of .
Three simple, but useful, jQuery methods for DOM manipulation are: text() - Sets or returns the text content of selected elements. html() - Sets or returns the content of selected elements (including HTML markup) val() - Sets or returns the value of form fields.
The . off() method removes event handlers that were attached with . on() .
live
binds the click
event to the DOM's document
element. As browser events bubble up through the DOM tree, the click event is triggered for any matching elements.
Here's a good article explaining it all.
http://www.alfajango.com/blog/the-difference-between-jquerys-bind-live-and-delegate/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With