-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathclick.xml
More file actions
113 lines (110 loc) · 3.78 KB
/
click.xml
File metadata and controls
113 lines (110 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?xml version="1.0"?>
<entries>
<desc>Bind an event handler to the "click" event, or trigger that event on an element.</desc>
<entry type="method" name="on" return="jQuery">
<title>click event</title>
<desc>Bind an event handler to the "click" event.</desc>
<signature>
<added>1.7</added>
<argument name=""click"" type="string">
<desc>The string <code>"click"</code>.</desc>
</argument>
<argument name="eventData" type="Anything" optional="true">
<desc>An object containing data that will be passed to the event handler.</desc>
</argument>
<argument name="handler" type="Function">
<desc>A function to execute each time the event is triggered.</desc>
<argument name="eventObject" type="Event" />
</argument>
</signature>
<longdesc>
<div class="warning">
<p>This page describes the <code>click</code> event. For the deprecated <code>.click()</code> method, see <a href="/click-shorthand/"><code>.click()</code></a>.</p>
</div>
<p>The <code>click</code> event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed and released. Any HTML element can receive this event.
For example, consider the HTML:</p>
<pre><code>
<div id="target">
Click here
</div>
<div id="other">
Trigger the handler
</div>
</code></pre>
<figure>
<img src="/resources/0042_05_03.png" alt=""/>
<figcaption>Figure 1 - Illustration of the rendered HTML</figcaption>
</figure>
<p>The event handler can be bound to any <code><div></code>:</p>
<pre><code>
$( "#target" ).on( "click", function() {
alert( "Handler for `click` called." );
} );
</code></pre>
<p>Now if we click on this element, the alert is displayed:</p>
<p>
<samp>Handler for `click` called.</samp>
</p>
<p>We can also trigger the event when a different element is clicked:</p>
<pre><code>
$( "#other" ).on( "click", function() {
$( "#target" ).trigger( "click" );
} );
</code></pre>
<p>After this code executes, clicking on <samp>Trigger the handler</samp> will also alert the message.</p>
<p>The <code>click</code> event is only triggered after this exact series of events:</p>
<ul>
<li>The mouse button is depressed while the pointer is inside the element.</li>
<li>The mouse button is released while the pointer is inside the element.</li>
</ul>
<p>This is usually the desired sequence before taking an action. If this is not required, the <code>mousedown</code> or <code>mouseup</code> event may be more suitable.</p>
</longdesc>
<example>
<desc>Hide paragraphs on a page when they are clicked:</desc>
<code><![CDATA[
$( "p" ).on( "click", function() {
$( this ).slideUp();
} );
]]></code>
<css><![CDATA[
p {
color: red;
margin: 5px;
cursor: pointer;
}
p:hover {
background: yellow;
}
]]></css>
<html><![CDATA[
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Yet one more Paragraph</p>
]]></html>
</example>
<example>
<desc>Trigger the click event on all the paragraphs on the page:</desc>
<code><![CDATA[
$( "p" ).trigger( "click" );
]]></code>
</example>
<category slug="events/mouse-events"/>
<category slug="version/1.0"/>
<category slug="version/1.7"/>
</entry>
<entry type="method" name="trigger" return="jQuery">
<title>click event</title>
<desc>Trigger the "click" event on an element.</desc>
<signature>
<added>1.0</added>
<argument name=""click"" type="string">
<desc>The string <code>"click"</code>.</desc>
</argument>
</signature>
<longdesc>
<p>See the description for <a href="#on1"><code>.on( "click", ... )</code></a>.</p>
</longdesc>
<category slug="events/mouse-events"/>
<category slug="version/1.0"/>
</entry>
</entries>