Created
March 30, 2012 13:50
-
-
Save tpthn/2251681 to your computer and use it in GitHub Desktop.
jQuery - Get multiple selected items from list
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
<select name="garden" multiple="multiple"> | |
<option>Flowers</option> | |
<option selected="selected">Shrubs</option> | |
<option>Trees</option> | |
<option selected="selected">Bushes</option> | |
<option>Grass</option> | |
<option>Dirt</option> | |
</select> | |
<script> | |
$("select").change(function () { | |
var str = ""; | |
$("select option:selected").each(function () { | |
str += $(this).text() + " "; | |
}); | |
$("div").text(str); | |
}) | |
.trigger('change'); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment