Reputation: 157
How do i get the value of an html5
attribute using jQuery ?
<button data-direction="next" data-next="2"></button>
I want to be able to get the newest set value of data-next
.
When i change the value dynamically using javascript and then try to get it using
$('[data-direction="next"][data-next]').data('next')
,
it always returns the data as set when loading the page not after being updated - in this case 2
.
Upvotes: 0
Views: 426
Reputation: 1310
I concur with @Pierre. Use the attr() method to retrieve the desired value.
A point to note, your selector could turn out to be slower. Check this article out.
Upvotes: 0
Reputation: 19071
$('[data-direction="next"][data-next]').attr('data-next')
should work..
Upvotes: 2