Created
August 13, 2012 12:51
-
-
Save andrijac/3340350 to your computer and use it in GitHub Desktop.
select element in jquery, reading values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// selected index in select (dropdown) | |
$.fn.selectedIndex = function () { | |
var index = 0; | |
this.each(function () { | |
index = +$(this).prop('selectedIndex'); | |
return false; | |
}); | |
return index; | |
}; | |
// selected value in select (dropdown) | |
$.fn.selectedValue = function () { | |
var value = 0; | |
this.each(function () { | |
value = $(this).find("option:selected").val(); | |
return false; | |
}); | |
return value; | |
}; | |
// select all items in listbox | |
$.fn.selectAllItems = function () { | |
this.each(function () { | |
$(this).find('option').attr("selected", "selected"); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment