Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does jQuery .live() work?

Tags:

jquery

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)

like image 533
bevacqua Avatar asked Jul 23 '11 14:07

bevacqua


People also ask

What is the difference between bind () and live () method in jQuery?

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.

What is the difference between on and live in jQuery?

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 .

What are the methods used in jQuery to change and manipulate HTML elements and attributes?

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.

Which event handler method would be used to remove an event handler that was attached with on function?

The . off() method removes event handlers that were attached with . on() .


1 Answers

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/

like image 157
Geoff Appleford Avatar answered Sep 22 '22 14:09

Geoff Appleford