Solved

Could you please explain live function in jquery

Posted on 2013-02-06
3
312 Views
Last Modified: 2013-02-11
Could you please explain live function in jquery and give me the understandable example
0
Comment
Question by:stmani2005
3 Comments
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 38862846
First thing,
The live() method was deprecated in jQuery version 1.7. Use the on() method instead.

live method registers the method which is generated runtime.

For example

http://jsfiddle.net/gtEeU/
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 38862883
0
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 38863379
live() is now deprecated and on() is the preferred function. Basically it's a way of binding events to elements.

The simplest way to bind a click event to elements is to use something like:

('.someElements').click(function() { do something when clicked });

which is often run when the page is first loaded. The above example binds a click event to all elements with a class of 'someElements'.

Now imagine somewhere in your code you have a function that creates a new element with a class of someElements (an AJAX call perhaps). This new element wont have the click event bound to it, because the code that binds the event was run on page load, and your new element didn't exist then. This is where on() comes in handy. You can attach delegated events and the above line of code would be better off as something like:

$('body').on('click', '.someElements', function() { do something when clicked });

Now the click event will run on all elements with a class of someElements (that exist within body), even if they are added after the code is fired.

Read all about it here -> http://api.jquery.com/on/
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now