Created
November 5, 2015 07:03
-
-
Save shameersn/0197352f3b0daf0666ef to your computer and use it in GitHub Desktop.
jquery how to get data attribute value of selected option
This file contains hidden or 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> | |
<option data-id="1">one</option> | |
<option data-id="2">two</option> | |
<option data-id="3">three</option> | |
</select> | |
You need to find the selected option: | |
$(this).find(':selected').data('id') | |
or | |
$(this).find(':selected').attr('data-id') | |
although the first method is preferred. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment