Hext0r
Hext0r

Reputation: 157

HTML5 custom attribute updated value

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

Answers (2)

gmajivu
gmajivu

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

Pierre
Pierre

Reputation: 19071

$('[data-direction="next"][data-next]').attr('data-next') should work..

Upvotes: 2

Related Questions