Tuesday, February 24, 2015

Select drop-down list in jquery

  Get selected value using class :-
$(".drop_down_class").val();


Get selected value using Id :-
$("#drop_down_id").val();


Get text of selected value :-
$("#drop_down_id").text();




Get value of nth option :-
$("#drop_down_id option:nth-child(1)")


Get index of selected option :-
$("#drop_down_id option:selected").index()


Set value using class :-
$('.drop_down_class').val('value');


Set value using Id :-
$('#drop_down_id').val('value');


Set value using text :-
var text = 'some_text';
$("#drop_down_id option").filter(function() { 
   return this.text == text }).attr('selected', true);

Set value using index :-
$("#drop_down_id").attr("selectedIndex", 3);

Add options in select drop down :-
$("#drop_down_id").append( $('').val("5").html("BUG")


Clear all options of select drop down list :-
$("#drop_down_id").empty();

Make drop down list disabled :-
$("#drop_down_id").attr("disabled", true);

No comments:

Post a Comment