figuedmundo figuedmundo - 2 years ago 88
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?

Answer Source
<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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download