Reputation: 135
I search to know how place a new select element at the second place of a select list
The hierarchy:
My function :
function classAppend(){
$('#email').append(
$('<option></option>').val('').addClass('new_address_mail').html("Add")
);
}
Some one know what is the option?
Upvotes: 6
Views: 6845
Reputation: 4358
$("<option value='x'>newly added</option>").insertAfter($("select option:first"));
Upvotes: 1
Reputation: 16848
Try this:
$('#email option:first').after($('<option />', { "value": '', text: 'My new option', class: 'new_address_mail' }));
Upvotes: 16
Reputation: 237817
You probably have to select the first child of #email
and insert your element with insertAfter
:
$('<option></option>')
.val('')
.addClass('new_address_mail')
.html("Add")
.insertAfter($('#email').children().first());
Upvotes: 2