jquery remove, bind, trigger element events

Source: Internet
Author: User

Unbind (type [, data])     //data is the function to be removed $ ('#btn'). Unbind (" Click " // Remove Click$ ('#btn'// Remove all

For a case that only needs to be triggered once and then immediately unbound, use one ()

$ ('#btn'). One ("click", function () {...});

Trigger action: the trigger () method triggers the specified event type for the selected element.

$ ('#btn'). Trigger ("click");

Trigger Custom Event: the bind () method adds one or more event handlers for the selected element and specifies the function to run when the event occurs.

$ ('#btn'). Bind ("myclick", function () {...});

Impersonation triggers the above binding function

$ ('#btn'). Trigger ("myclick");

Pass Data trigger (EVENT,[PARAM1,PARAM2,...])

$ ('#btn'). Bind ("myclick", Function (event, Message1,message2) () {...}); $ ('#btn'). Trigger ("myclick", [" Pass it to Message1 "," passed to Message2"]);

Triggering the execution of the default action

$ ("input"). Trigger ("Focus"); // not only does it trigger the focus event that the input element binds to, it also triggers the default action--Get Focus

Triggers only binding events, not browser default actions

$ ("input"). Triggerhandler ("Focus"); // triggers only binding events, not browser default actions

Other usage

Binding multiple Event types

$ ("div"). Bind ("mouseover mouseout", function () {...});

To add an event namespace

$ ("div"). Bind ("click.plugin", function () {...});

Add a namespace after the event type you are binding so that you only need to specify the namespace when you delete the event.

$ ("div"). Unbind (". Plugin");   // Delete the event within the space $ ("div"). Trigger ("click! " // trigger so does not include the click Method in the namespace

If it is included in the namespace, it will also be triggered

$ ("div"). Trigger ("click");

Cancel or bind a function

$ ('div'). Bind ('click', recommandproduct); // bind the Recommandproduct function $ ('div') for Div. Unbind ('click ', recommandproduct); // Cancel the Recommandproduct function

jquery remove, bind, trigger element events

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.