Opened 15 years ago
Closed 13 years ago
#3622 closed bug (invalid)
Bug with CSS Selector E[foo] on Option elements
Reported by: | djvirgen | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.3 |
Component: | selector | Version: | 1.2.6 |
Keywords: | Cc: | djvirgen, flesler | |
Blocked by: | Blocking: |
Description
HTML:
<select id="theSelect">
<option>Select a color</option> <option value="blue">Blue</option> <option value="red">Red</option>
</select>
Given the above HTML, the following CSS selector incorrectly returns all 3 options:
$('#theSelect option[value]').length; 3
While the first option would submit a value when the form is submitted, it technically does not have a value attribute.
According to the W3C spec [1], the selector E[foo] should return E elements that contain a foo attribute.
Change History (4)
comment:1 Changed 15 years ago by
Cc: | djvirgen flesler added |
---|
comment:2 Changed 15 years ago by
I have just tested it with the nightly build, and it is still reporting an incorrect number of matched elements.
Test code:
console.log('Number of options with a "value" attribute: ' + $('option[value]').length); incorrectly reports 3
HTML:
<select name="test">
<option>No Value Attribute</option> <option value="foo">Foo</option> <option value="bar">Bar</option>
</select>
comment:3 Changed 15 years ago by
var el = $('<select><option>text</option></select>').find('option')[0]; el.value; //returns "text" el.getAttribute('value'); //returns: null
In both 1.2.6 and 1.3b2 first the element's property is checked, which returns "text" instead of undefined even if there isn't a value attribute, so there won't be any further checks with getAttribute. Otherwise using .val()
would return "text" on the element but you wouldn't be able to select it with the attribute filter.
comment:4 Changed 13 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
http://jsfiddle.net/dmethvin/BQQQx/
As balazs.endresz said, this is expected behavior. If jQuery didn't match against the value *property* then the selector would only match the initial value attribute.
Can you try with this version of jQuery ?