I have html select,
In POJS you'd use insertBefore()
, e.g.
var select = document.getElementById('mySelect');
var opt = new Option('', 'my-option');
select.insertBefore(opt, select.firstChild);
First, you mean append, rather than appendTo. append
adds the content of the parameter to the selection; appendTo
appends the selection to the element designated in the parameter.
Second, perhaps intuitively, you can use prepend:
$('#myselect').prepend($('<option>my-option</option>'));
Use prependTo()
You might have meant this $('#myselect').prependTo($('my-option'));//typo?
$('#myselect').prepend($('<option>my-option</option>'));
http://api.jquery.com/prependTo
http://api.jquery.com/prepend/
But your code is actually the other way around. This might be a typo. In any case, the methods available are prepend()
and prependTo()