Add options to the end of select element
$('#elementid').append('<option value="1">UK</option>');
Add options to the start of select element
$('#elementid').prepend('<option value="0">Before UK</option>');
Add options after selected index
$("#elementid option:eq(0)").after("<option value='4'>US</option>);"
Add options before selected index
$("#elementid option:eq(3)").before("<option value='5'>India</option>")
Replace items at a certain index
$("#elementid option:eq(1)").replaceWith("<option value='2'>China</option>")
Remove option at specified index
$("#elementid option:eq(0)").remove()
Remove first option
$("#elementid option:first").remove()
Remove last option
$("#elementid option:last").remove()
Remove option with a specific value
$("#elementid option:[value='UK']").remove()
http://comp345.awardspace.com/select_element_cheatsheet.pdf
No comments:
Post a Comment