Side navigation
#14858 closed bug (fixed)
Opened March 06, 2014 07:05PM UTC
Closed March 20, 2014 07:56PM UTC
jQuery 1.11.0 and up - .val() of option with no value attribute returning white-space
Reported by: | hovenj@gmail.com | Owned by: | dmethvin |
---|---|---|---|
Priority: | high | Milestone: | 1.11.1/2.1.1 |
Component: | attributes | Version: | 1.11.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Beginning with jQuery 1.11.0 (and continuing only in the 1.x branch), using .val() on an option with no value attribute returns the entire text of the option, including white-space.
<select> <option selected> </option> </select> Length of selected option value: <span id="result"></span> <script type="text/javascript"> var $r = $('#result'), $o = $('select option:selected'); $r.text( $o.val().length ); </script>
In 1.10.1 and 2.x (edge), this returns 0. In 1.11.0 and forward, this returns 12.
Attachments (0)
Change History (7)
Changed March 06, 2014 07:09PM UTC by comment:1
Changed March 06, 2014 07:12PM UTC by comment:2
Also reproduced in Firefox 25.0.1 on Windows 7 and IE 10 (.0.9200.16798) on Windows 8.
Changed March 06, 2014 07:31PM UTC by comment:3
Val on options changed over to jQuery.text in the following commit:
https://github.com/jquery/jquery/commit/92cbf5362cfe4fe52e919eecfebe8ecbe27ee5e3
It looks like jQuery.text()'s behavior is consistent across these versions, so maybe this commit was bad?
Updated fiddle:
Changed March 06, 2014 07:57PM UTC by comment:4
I've added a pull request based on my observations.
https://github.com/jquery/jquery/pull/1531
Changed March 16, 2014 03:59PM UTC by comment:5
component: | unfiled → attributes |
---|---|
milestone: | None → 1.11.1/2.1.1 |
priority: | undecided → high |
status: | new → open |
Changed March 17, 2014 04:29PM UTC by comment:6
owner: | → dmethvin |
---|---|
status: | open → assigned |
Changed March 20, 2014 07:56PM UTC by comment:7
resolution: | → fixed |
---|---|
status: | assigned → closed |
Reproduced in IE9 and Chrome 34.0.1847.45 beta-m, both on Windows 7.
I expected non-significant white-space to be excluded from the value. Based on other versions, you wouldn't even expect a single space.