Skip to content

Instantly share code, notes, and snippets.

@shameersn
Created November 5, 2015 07:03
Show Gist options
  • Save shameersn/0197352f3b0daf0666ef to your computer and use it in GitHub Desktop.
Save shameersn/0197352f3b0daf0666ef to your computer and use it in GitHub Desktop.
jquery how to get data attribute value of selected option
<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