Example of trigger () method usage in jQuery, jquerytrigger

Source: Internet
Author: User

Example of trigger () method usage in jQuery, jquerytrigger

This document describes how to use the trigger () method in jQuery. Share it with you for your reference. The specific analysis is as follows:

This method triggers events of the specified type of matching element.

Syntax structure 1:
Specifies the event type triggered by the matching element.
Copy codeThe Code is as follows: $ (selector). trigger (event, param1, param2 ,...)

Parameter List:

Parameters Description
Event Specifies the event to be triggered by the specified element.
It can be a Custom Event (attached using the bind () function) or any standard event.
Param Optional. Additional parameters passed to the event handler.
Additional parameters are particularly useful for custom events.

Instance code:

Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> trigger () function-helper's house </title>
<Style type = "text/css">
Div {
Width: 200px;
Height: 200px;
Border: 1px solid blue;
}
</Style>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Div"). click (function (){
$ ("Div"). append ("added content ");
});
$ ("Button"). click (function (){
$ ("Div"). trigger ("click ");
})
})
</Script>
</Head>
<Body>
<Div> </div>
<Button> click activation event </button>
</Body>
</Html>

When you click the button, you can start the click event on the div and then execute the click event processing function.

Syntax structure 2:

The event object is used as a parameter to specify the event type to be triggered by the matching element.
Copy codeThe Code is as follows: $ (selector). trigger (eventObj)

Parameter List:

Parameters Description
EventObj The event object specifies the function that runs when an event occurs.

Instance code:

Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> trigger () function-helper's house </title>
<Style type = "text/css">
Div {
Width: 200px;
Height: 200px;
Border: 1px solid blue;
}
</Style>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Div"). click (function (){
$ ("Div"). append ("added content ");
});
Var e = jQuery. Event ("click ");
$ ("Button"). click (function (){
$ ("Div"). trigger (e );
})
})
</Script>
</Head>
<Body>
<Div> </div>
<Button> click activation event </button>
</Body>
</Html>

I hope this article will help you with jQuery programming.

Related Article

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.