2808 explained code solutions for 75 technologies


htmlUsing data attribute


<div id="el" data-name="Donald"></div>
<script> console.log(document.querySelector('#el').dataset.name); </script>ctrl + c
div

sample element

id="el"

id of sample element

data-name

data attribute named name

Donald

value of name data attribute

.dataset.name

access name property of #el element in javascript