figuedmundo figuedmundo - 9 months ago 37
Javascript Question

get the value of html5 <data-something="value"> with jquery

The other day I was reading the answers here in stackoverflow and I read, "jquery can get the value of the html5

", I read this when I was looking for something else so I just read and don't analyse this. And now I really need accomplish this task.

The question is: is it posible or I just misunderstand the reading?

<div id="test" data-key="abcd">hahahah</div>

<script type="text/javascript">
var value = $("#test").data("key");
alert(value); //This will show you "abcd"

I think data isn't only for HTML5 but also in HTML4