Bug Tracker

Opened 9 years ago

Closed 9 years ago

#14426 closed bug (notabug)

Prepend and Each Doesn't Add Option to Select

Reported by: [email protected] Owned by: [email protected]
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"));

$("[id*=FT_DDL_COMP0]")[0].options[0].selected = true

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 Rick Waldron

Owner: set to [email protected]
Status: newpending

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.

comment:2 Changed 9 years ago by 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

comment:3 in reply to:  2 Changed 9 years ago by Rick Waldron

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

http://gyazo.com/4b5ebd852696eb5a9a88b41e07a05797.png

comment:4 Changed 9 years ago by anonymous

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 Rick Waldron

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 Changed 9 years ago by anonymous

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 in reply to:  6 Changed 9 years ago by Rick Waldron

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 anonymous

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 Rick Waldron

Resolution: notabug
Status: pendingclosed

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/

Note: See TracTickets for help on using tickets.