javascript - Get "data-something" from an <option> tag contained in <select> -


i have html

<select id="something">     <option value="1" data-something="true">something true</option>     <option value="2" data-something-else="false">something else false</option> </select> 

and jquery snippet i'm trying values data-* attributes:

$(document).ready(function() {     $('body').on('change', 'select#something', function() {         console.log( $(this).data('something') ); // undefined         console.log( $(this).data('something-else') ); // undefined     }); }); 

how data-* attribute values jquery?

this select element.

console.log($(this).find(":selected").data("something")) 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -