1. Get selected items:
Get the Value of the selected item:
$('select#sel option:selected').val();
or
$('select#sel').find('option:selected').val();
Get the Text value of the selected item:
$('select#seloption:selected').text();
or
$('select#sel').find('option:selected').text();
2. Get the index value of the currently selected item:
$('select#sel').get(0).selectedIndex;
3. Get the maximum index value of the current option:
$('select#sel option:last').attr("index")
4. Get the length of DropdownList:
$('select#sel')[0].options.length;
or
$('select#sel').get(0).options.length;
5. Set the first option as the selected value:
$('select#sel option:first').attr('selected','true')
or
$('select#sel')[0].selectedIndex = 0;
6. Set the last option as the selected value:
$('select#sel option:last).attr('selected','true')
7. Set any option as the selected value based on the index value:
$('select#sel')[0].selectedIndex =index value; index value=0,1,2....
8. Set the option with Value=4 as the selected value:
$('select#sel').attr('value','4');
or
$("select#sel option[value='4']").attr('selected', 'true');
9. Delete option with Value=3:
$("select#sel option[value='3']").remove();
10. Which option to delete:
$(" select#sel option ").eq(index value).remove(); index value=0,1,2....
If you want to delete the 3rd Radio:
$(" select#sel option ").eq(2).remove();
11. Delete the first option:
$(" select#sel option ").eq(0).remove();
or
$("select#sel option:first").remove();
12. Delete the last option:
$("select#sel option:last").remove();
13. Delete dropdownlist:
$("select#sel").remove();
14. Add an option after select:
$("select#sel").append("f ");
15. Add an option in front of select:
$("select#sel").prepend("0 ");
16. Traverse options:
$(' select#sel option ').each(function (index, domEle) {
//Write code
});