Ticket #4047 (closed bug: worksforme)
Selector, <select> and val() returns inconsistent value
| Reported by: | nminale | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.3.2 |
| Component: | unfiled | Version: | 1.3.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Hi, I have the following code, <div id="testDiv"> <select id="testSelect"> <option value="1">One</option> <option value="2">Two</option> </select> <input type="button" id="testBtn" value="Test"> </div>
On the page, when I select "Two" from the drop down list and use JQuery to get the value of <select>, the result is inconsistent.
- $("div[id='testDiv'] select[id='testSelect']").val(), it returns "1".
- $("#testDiv").find("#testSelect").val(), it returns "1".
- $("#testSelect").val(), it returns "2".
Using Firebug, I saw the selectors from A and B actually return all <option> elements... So naturally, it picks the value of the first option..
With JQuery 1.2.6, A, B and C return same value.
Please advise.
Thank you.
Attachments
Change History
Changed 4 years ago by dmethvin
-
attachment
test-4047.html
added
comment:1 Changed 4 years ago by dmethvin
- Status changed from new to closed
- Resolution set to worksforme
I've attached a complete test case that seems to work fine for me. You mentioned Firebug so I assume you tested in Firefox, but If I've misinterpreted the problem, please reopen and attach a test case that demonstrates the problem.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Working example