Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript get custom attribute value from element

<!-- TRYING TO ACCESS TO CUSTOM ATTRIBUTES WITH JAVASCRIPT ? -->

<article
  id="electric-cars"
  data-columns="3"
  data-index-number="12314"
  data-parent="cars">
</article>

<script>
// const article = document.getElementById("electric-cars")
article.dataset.columns // "3"
article.dataset.indexNumber // "12314"
article.dataset.parent // "cars"
</script>
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #javascript #custom #attribute #element
ADD COMMENT
Topic
Name
6+3 =