Alex Rivera | Logout

How to insert option at specified index of select(Multiple) in html?

Asked 2011-08-02T13:27:34.943
33

How can I insert an option element at a specified index in a <select multiple> element?

Thanks

Edit
Report

1 Answer

2

Here's a way you can do it:

var myOption = "<option>Dynamic Option</option>";
var index = 2;
$(myOption).insertBefore("select option:nth-child("+index+")");

fiddle example

answered 2011-08-02T13:47:21.747

Your Answer