Skip to main content

Bug Tracker

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: Owned by: dmethvin
Priority: high Milestone: 1.11.1/2.1.1
Component: attributes Version: 1.11.0
Keywords: Cc:
Blocked by: Blocking:

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.

  <option selected>

Length of selected option value: <span id="result"></span>

<script type="text/javascript">
 $r = $('#result'),
 $o = $('select option:selected');
$r.text( $o.val().length );

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 anonymous comment:1

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.

Changed March 06, 2014 07:12PM UTC by anonymous 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 anonymous comment:3

Val on options changed over to jQuery.text in the following commit:

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 anonymous comment:4

I've added a pull request based on my observations.

Changed March 16, 2014 03:59PM UTC by dmethvin comment:5

component: unfiledattributes
milestone: None1.11.1/2.1.1
priority: undecidedhigh
status: newopen

Changed March 17, 2014 04:29PM UTC by dmethvin comment:6

owner: → dmethvin
status: openassigned

Changed March 20, 2014 07:56PM UTC by John Hoven comment:7

resolution: → fixed
status: assignedclosed

Attributes: Trim whitespace from option text when returned as a value

Fixes #14858

Ref #14686

Closes gh-1531

(cherry picked from commit 9ec429cf6270e455aba4eba85f4db80e633806b6)



Changeset: 541e7349b6533eb533c15d17e3e9e432e4a719ea