You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<desc>An object containing data that will be passed to the event handler.</desc>
16
15
</argument>
@@ -19,11 +18,7 @@
19
18
<argumentname="eventObject"type="Event" />
20
19
</argument>
21
20
</signature>
22
-
<signature>
23
-
<added>1.0</added>
24
-
</signature>
25
21
<longdesc>
26
-
<p>This method is a shortcut for <code>.on( "change", handler )</code> in the first two variations, and <code>.trigger( "change" )</code> in the third.</p>
27
22
<p>The <code>change</code> event is sent to an element when its value changes. This event is limited to <code><input></code> elements, <code><textarea></code> boxes and <code><select></code> elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.</p>
28
23
<p>For example, consider the HTML:</p>
29
24
<pre><code>
@@ -40,34 +35,34 @@
40
35
</code></pre>
41
36
<p>The event handler can be bound to the text input and the select box:</p>
42
37
<pre><code>
43
-
$( ".target" ).change(function() {
44
-
alert( "Handler for .change() called." );
45
-
});
38
+
$( ".target" ).on( "change", function() {
39
+
alert( "Handler for `change` called." );
40
+
});
46
41
</code></pre>
47
-
<p>Now when the second option is selected from the dropdown, the alert is displayed. It is also displayed if you change the text in the field and then click away. If the field loses focus without the contents having changed, though, the event is not triggered. To trigger the event manually, apply <code>.change()</code> without arguments:</p>
42
+
<p>Now when the second option is selected from the dropdown, the alert is displayed. It is also displayed if you change the text in the field and then click away. If the field loses focus without the contents having changed, though, the event is not triggered. To trigger the event manually, use <code>.trigger( "change" )</code>:</p>
48
43
<pre><code>
49
-
$( "#other" ).click(function() {
50
-
$( ".target" ).change();
51
-
});
44
+
$( "#other" ).on( "click", function() {
45
+
$( ".target" ).trigger( "change" );
46
+
});
52
47
</code></pre>
53
48
<p>After this code executes, clicks on <samp>Trigger the handler</samp> will also alert the message. The message will display twice, because the handler has been bound to the <code>change</code> event on both of the form elements.</p>
54
49
<p>As of jQuery 1.4, the <code>change</code> event bubbles in Internet Explorer, behaving consistently with the event in other modern browsers.</p>
55
50
<divclass="warning">
56
-
<p><strong>Note: </strong>Changing the value of an input element using JavaScript, using <ahref="/val"><code>.val()</code></a> for example, won't fire the event.</p>
51
+
<p><strong>Note: </strong>Changing the value of an input element using JavaScript, using <ahref="/val"><code>.val()</code></a> for example, won't fire the event.</p>
57
52
</div>
58
53
</longdesc>
59
54
<example>
60
55
<desc>Attaches a change event to the select that gets the text for each selected option and writes them in the div. It then triggers the event for the initial text draw.</desc>
61
56
<code><![CDATA[
62
57
$( "select" )
63
-
.change(function () {
58
+
.on( "change", function() {
64
59
var str = "";
65
-
$( "select option:selected" ).each(function() {
60
+
$( "select option:selected" ).each(function() {
66
61
str += $( this ).text() + " ";
67
-
});
62
+
});
68
63
$( "div" ).text( str );
69
-
})
70
-
.change();
64
+
})
65
+
.trigger( "change" );
71
66
]]></code>
72
67
<css><![CDATA[
73
68
div {
@@ -89,13 +84,31 @@ $( "select" )
89
84
<example>
90
85
<desc>To add a validity test to all text input elements:</desc>
<desc>An object containing data that will be passed to the event handler.</desc>
16
15
</argument>
@@ -19,9 +18,6 @@
19
18
<argumentname="eventObject"type="Event" />
20
19
</argument>
21
20
</signature>
22
-
<signature>
23
-
<added>1.0</added>
24
-
</signature>
25
21
<longdesc>
26
22
<p>This method is a shortcut for <code>.on( "select", handler )</code> in the first two variations, and <code>.trigger( "select" )</code> in the third.</p>
27
23
<p>The <code>select</code> event is sent to an element when the user makes a text selection inside it. This event is limited to <code><input type="text"></code> fields and <code><textarea></code> boxes.</p>
@@ -35,19 +31,19 @@
35
31
</div></code></pre>
36
32
<p>The event handler can be bound to the text input:</p>
37
33
<pre><code>
38
-
$( "#target" ).select(function() {
39
-
alert( "Handler for .select() called." );
40
-
});
34
+
$( "#target" ).on( "select", function() {
35
+
alert( "Handler for `select` called." );
36
+
});
41
37
</code></pre>
42
-
<p>Now when any portion of the text is selected, the alert is displayed. Merely setting the location of the insertion point will not trigger the event. To trigger the event manually, apply <code>.select()</code> without an argument:</p>
38
+
<p>Now when any portion of the text is selected, the alert is displayed. Merely setting the location of the insertion point will not trigger the event. To trigger the event manually, use <code>.trigger( "select" )</code>:</p>
43
39
<pre><code>
44
-
$( "#other").click(function() {
45
-
$( "#target" ).select();
46
-
});
40
+
$( "#other").on( "click", function() {
41
+
$( "#target" ).trigger( "select" );
42
+
});
47
43
</code></pre>
48
44
<p>After this code executes, clicks on the Trigger button will also alert the message:</p>
49
45
<p>
50
-
<samp>Handler for .select() called.</samp>
46
+
<samp>Handler for `select` called.</samp>
51
47
</p>
52
48
<p>In addition, the default <code>select</code> action on the field will be fired, so the entire text field will be selected.</p>
53
49
<divclass="warning">
@@ -57,9 +53,9 @@ $( "#other").click(function() {
57
53
<example>
58
54
<desc>To do something when text in input boxes is selected:</desc>
59
55
<code><![CDATA[
60
-
$( ":input" ).select(function() {
56
+
$( ":input" ).on( "select", function() {
61
57
$( "div" ).text( "Something was selected" ).show().fadeOut( 1000 );
0 commit comments