Saturday, March 14, 2009

JQuery: Manipulate items in dropdownlist

To select items in dropdownlist, we have several ways.

1. Select items by setting the selected value
$('#dropdown').val('option1');

2.Select items by setting the selected index
$('#dropdown').attr("selectedIndex", 3);


To add items (option) in dropdownlist:
$('#dropdown').append($('').val(val).html(html));

Check whether an item (option) is exist in the dropdownlist:
$('#dropdown option[value= yourvalue]').length > 0

No comments: