Answers for "use data attribute in 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
0

html data attribute

<a data-color="blue">
  	This tag contains a user-defined color attribute
</a>

<div data-link="https://github.com/k-vernooy">
	This tag contains a data attribute with a link
</div>
Posted by: Guest on February-22-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language