-
Notifications
You must be signed in to change notification settings - Fork 264
val: Remove use of nonstandard selectors #994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,20 +13,20 @@ | |
<longdesc> | ||
<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 called on an empty collection, it returns <code>undefined</code>.</p> | ||
<p>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), <code>.val()</code> returns an array containing the value of each selected option. <strong>As of jQuery 3.0</strong>, if no options are selected, it returns an empty array; <strong>prior to jQuery 3.0</strong>, it returns <code>null</code>.</p> | ||
<p>For selects, checkboxes and radio buttons, 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> | ||
<p>For selects, checkboxes and radio buttons, you can also use the <a href="/checked-selector/">:checked</a> selector to get at values. For example:</p> | ||
<pre><code> | ||
|
||
// Get the value from a dropdown select | ||
$( "select.foo option:selected").val(); | ||
$( "select.foo option:checked").val(); | ||
|
||
// Get the value from a dropdown select even easier | ||
$( "select.foo" ).val(); | ||
|
||
// Get the value from a checked checkbox | ||
$( "input:checkbox:checked" ).val(); | ||
$( "input[type=checkbox]:checked" ).val(); | ||
|
||
// Get the value from a set of radio buttons | ||
$( "input:radio[name=bar]:checked" ).val(); | ||
$( "input[type=radio][name=bar]:checked" ).val(); | ||
</code></pre> | ||
<div class="warning"> | ||
<p><strong>Note: </strong> At present, using <code>.val()</code> on <code><textarea></code> elements strips carriage return characters from the browser-reported value. When this value is sent to the server via XHR, however, carriage returns are preserved (or added by browsers which do not include them in the raw value). A workaround for this issue can be achieved using a valHook as follows:</p> | ||
|
@@ -131,11 +131,11 @@ $( "input" ) | |
<p>Setting values using this method (or using the native <code>value</code> property) does not cause the dispatch of the <code>change</code> event. For this reason, the relevant event handlers will not be executed. If you want to execute them, you should call <code>.trigger( "change" )</code> after setting the value.</p> | ||
<p>The <code>.val()</code> method allows setting the value by passing in a function. As of jQuery 1.4, the function is passed two arguments, the current element's index and its current value: </p> | ||
<pre><code> | ||
$( "input:text.items" ).val(function( index, value ) { | ||
return value + " " + this.className; | ||
$( "input[type=text].tags" ).val(function( index, value ) { | ||
return value.trim(); | ||
}); | ||
</code></pre> | ||
<p>This example appends the string " items" to the text inputs' values.</p> | ||
<p>This example removes leading and trailing whitespace from the text inputs' values.</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "inputs' values." ->"inputs' values. Only inputs having |
||
</longdesc> | ||
<example> | ||
<desc>Set the value of an input box.</desc> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"to get at values" -> "to get their values"?