Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Thanks

like image 600
Dipak Avatar asked Aug 02 '11 13:08

Dipak


People also ask

How do you style the option of an HTML select element?

You can use inline styles to add custome styling to <option> tags. For eg : <option style="font-weight:bold;color:#09C;">Option 1</option> This will apply the styles to this particular <option> element only.

How do you append to a select option?

Method 1: Append the option tag to the select boxThe select box is selected with the jQuery selector and this option is added with the append() method. The append() method inserts the specified content as the last child of the jQuery collection. Hence the option is added to the select element.

How do you select a particular option in a select element in JavaScript?

Use the selectedIndex and value to get the index and value of the selected option. The HTMLOptionElement represents the <option> element. If the option is selected, the selected property is true. The selectedText and selectedValue properties return the text and value of the selected option.


1 Answers

$("select option").eq(index).before($("<option></option>").val(val).html(text)); 
like image 168
Corneliu Avatar answered Oct 09 '22 02:10

Corneliu