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?
<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
You can use data()
and have jQuery attempt to decode the type and return the typed value.
If you want the raw string, use attr("data-x")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With