Answers for "what are custom data attributes html"

1

custom data attributes html

<div data-myvar="hello world"</div>
<script>
 //Note: attribute in html will force lowercase, make sure all letters are lower
  var element = document.querySelector("div");
  console.log(element.dataset.myvar);
  //outputs: hello world
</script>
Posted by: Guest on October-08-2021

Code answers related to "what are custom data attributes html"

Code answers related to "Javascript"

Browse Popular Code Answers by Language