Reputation: 5525
I have this code :
HTML
<select disabled class="kurir full-width" data-init-plugin="select2" name="kurir" data-productid="316">
...
</select>
jQuery
$(".kurir").change(function() {
var productid = $(this).getAttribute('data-productid');
alert (productid);
});
Why I can't get 316
from data-productid
? What did I missed here?
Thank you.
Upvotes: 1
Views: 88
Reputation: 518
.getAttribute is the javascript method we can't use it is jquery object method.
so you can use it below syntax- this.getAttribute('data-productid');
Upvotes: 3
Reputation: 20740
You can get attribute value like following.
this.getAttribute('data-productid')
Or
$(this).attr('data-productid')
Upvotes: 3