JQuery live (type, fn) delegate event implementation

Source: Internet
Author: User

Currently, click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, and keyup are supported.
Blur, focus, mouseenter, mouseleave, change, and submit are not supported.
Unlike bind (), live () can only bind one event at a time.
This method is similar to the traditional bind method. The difference is that using live to bind events will bind events to all current and future elements on the page (using the delegate method ). For example, if you bind a click event to all the likes on the page with live. When a new li is added to this page, the click event is still available for the newly added li. Instead of re-binding events to the newly added elements.
. Live () is similar to the popular liveQuery plug-in, but there are several major differences:
*. Live currently only supports a subset of all events. For the list of supported events, see the preceding description.
*. Live does not support callback functions in the "no event" style provided by liveQuery .. Live can only be bound to event handlers.
*. Live does not have "setup" or "cleanup" processes. Because all events are delegate rather than directly bound to elements.
To remove an event bound with live, use the die method.
Return Value
JQuery
Parameters
Type (String): one or more event names separated by Spaces
Fn (Function): The event processing Function to be bound.
Example
The p generated by clicking still has the same function.
HTML code:
<P> Click me! </P>
JQuery code:
Copy codeThe Code is as follows:
$ ("P"). live ("click", function (){
$ (This). after ("<p> Another paragraph! </P> ");
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.