How to get selected option data attribute using jQuery
If my HTML is like that:
<select class="form-control" name="user_name" id="user_name" multiple> <option value="">Select</option> <option value="1" data-name="Val 1" selected="selected">Val 1</option> <option value="2" data-name="Val 2">Val 2</option> <option value="3" data-name="Val 3" selected="selected">Val 3</option> <option value="4" data-name="Val 4">Val 4</option> <option value="5" data-name="Val 5" selected="selected">Val 5</option> </select>
How can I get data attribute value from the selected options using jQuery?
Question and answer is powered by AnsPress.io