I have html select,
<select id="myselect">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
I need to add new option in this select.
If I try like this:
$('#myselect').appendTo($('<option>my-option</option>'));
the my-option have added to the end
<select id="myselect">
<option>1</option>
<option>2</option>
<option>3</option>
<option>my-option</option>
</select>
How can I add an option in the beginning (as first)?
Like this:
<select id="myselect">
<option>my-option</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
First, you mean
append, rather thanappendTo.appendadds the content of the parameter to the selection;appendToappends the selection to the element designated in the parameter.Second, perhaps intuitively, you can use
prepend: