Skip to content

Instantly share code, notes, and snippets.

@yblee85
Last active August 29, 2015 14:00
Show Gist options
  • Save yblee85/11220380 to your computer and use it in GitHub Desktop.
Save yblee85/11220380 to your computer and use it in GitHub Desktop.
jQuery from 1.9 select option
html
<select id="select_id" value="">
<option value=""></option>
<option value="VALUE1">Value 1 for display</option>
<option value="VALUE2">Value 2 for display</option>
</select>
js
$("#select_id option[value=VALUE1]").prop('selected', true)
@yblee85
Copy link
Author

yblee85 commented Feb 27, 2015

when you want to get value
$("#select_id :selected").val() -> VALUE1 or VALUE2
$("#select_id :selected").text() -> Value 1 for display or Value 2 for display

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment