Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<div id="box" data-count="0"></div> <script> // .attr() reads and writes the DOM attribute $("#box").attr("data-count", 5); console.log($("#box").attr("data-count")); // "5" (string) // .data() uses jQuery cache — DOM not updated $("#box").data("count", 10); console.log($("#box").data("count")); // 10 (number) console.log($("#box").attr("data-count")); // still "5" </script>
Result
Open