Opened 9 years ago
Closed 9 years ago
#14426 closed bug (notabug)
Prepend and Each Doesn't Add Option to Select
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.10.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
When I do this it works fine $("[id*=FT_DDL_COMP0]").prepend(new Option("CHOOSE"));
This combines the added options with the first existing one. var cbos = $("[id*=FT_DDL_COMP]")
$.each(cbos, function (index, item) {
$(item[0]).prepend("<option value= selected='selected'>CHOOSE</option>")
});
Change History (9)
comment:1 Changed 9 years ago by
Owner: | set to [email protected]… |
---|---|
Status: | new → pending |
comment:2 follow-up: 3 Changed 9 years ago by
I added the code to jsfiddle but how do I save it? Also, I put in a radio button to show you my bug but the event didn't call the function I added. Thanks. Steve
comment:3 Changed 9 years ago by
Replying to anonymous:
I added the code to jsfiddle but how do I save it? Also, I put in a radio button to show you my bug but the event didn't call the function I added. Thanks. Steve
Click the "save" button
comment:4 Changed 9 years ago by
OK. I created an account so I got the save button and saved it at http://jsfiddle.net/VajdaS/5BnB3/ The radio buttons don't call my function and I don't know why and I can't debug. When you press the "good" radio button it calls the "good" code. Thanks. Steve
comment:5 Changed 9 years ago by
Thank you for providing the example on jsfiddle—can you please reduce the code to smallest possible unit that illustrates the bug? Thanks!
comment:6 follow-up: 7 Changed 9 years ago by
OK. I made a real simple version at http://jsfiddle.net/VajdaS/7jqFd/ I've never used JSFiddle before. That was interesting. Thanks.
comment:7 Changed 9 years ago by
Replying to anonymous:
OK. I made a real simple version at http://jsfiddle.net/VajdaS/7jqFd/ I've never used JSFiddle before. That was interesting. Thanks.
This has no version of jQuery selected?
It's still not clear to me what the issue is—can you clear define 1) the expected behaviour, and 2) the actual behaviour. Thanks
comment:8 Changed 9 years ago by
OK I copied the previous after seting the ref to Jquery edge at http://jsfiddle.net/VajdaS/tVTzn/. I added the CHOOSE option to both sets of drop downs but when I used the $each function it combined CHOOSE with the first existing option which is NONE.
comment:9 Changed 9 years ago by
Resolution: | → notabug |
---|---|
Status: | pending → closed |
This isn't a bug. item[0] refers to the first <option>
child of the <select>
and then you're prepending a new element to the beginning of the inside of that <option>
. Take a look: http://jsfiddle.net/rwaldron/nCRVX/
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket! Be sure to test against the "jQuery (edge)" version to ensure the issue still exists—you may need to change this to a specific version depending on the test case.
To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to begin.