Skip to content

Commit d5e6e58

Browse files
committed
Fix documentation for .val()
1 parent 93110b7 commit d5e6e58

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

entries/val.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<longdesc>
1414
<p>The <code>.val()</code> method is primarily used to get the values of form elements such as <code>input</code>, <code>select</code> and <code>textarea</code>. When the first element in the collection is a <code>select-multiple</code> (i.e., a <code>select</code> element with the <code>multiple</code> attribute set), it returns an array containing the value of each selected option, or <code>null</code> if no options are selected. When called on an empty collection, it returns <code>undefined</code>.</p>
1515
<p>For selects and checkboxes, you can also use the <a href="/selected-selector/">:selected</a> and <a href="/checked-selector/">:checked</a> selectors to get at values, for example:</p>
16+
<p><strong>jQuery 3</strong> changes the behavior of this method to return an empty array if a collection is a <code>select-multiple</code> and no options are selected.</p>
1617
<pre><code>
1718
// Get the value from a dropdown select
1819
$( "select.foo option:selected").val();
@@ -43,6 +44,8 @@ $.valHooks.textarea = {
4344
function displayVals() {
4445
var singleValues = $( "#single" ).val();
4546
var multipleValues = $( "#multiple" ).val() || [];
47+
// When using jQuery 3:
48+
// var multipleValues = $( "#multiple" ).val()
4649
$( "p" ).html( "<b>Single:</b> " + singleValues +
4750
" <b>Multiple:</b> " + multipleValues.join( ", " ) );
4851
}

0 commit comments

Comments
 (0)