Here it's my html code
<select class="data">
<option value="This is my test code" data-id='123'/>
</select>
Now I want to access a data attribute in jquery here it's my jquery code
$( ".data" ).change(function() {
var Id = $(this).data("id")
alert("id: "+Id);
});
but when I'm tried this one it's give a undefine value. please help me.
Use this
$( ".data" ).change(function() {
var Id = $(this).find('option:selected').data("id")
alert("id: "+Id);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With