figuedmundo figuedmundo - 6 months ago 10
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

<data-something='value'>
", 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?

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

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

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

Comments