Skip to content

Instantly share code, notes, and snippets.

@tpthn
Created March 30, 2012 13:50
Show Gist options
  • Save tpthn/2251681 to your computer and use it in GitHub Desktop.
Save tpthn/2251681 to your computer and use it in GitHub Desktop.
jQuery - Get multiple selected items from list
<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