Answers for "set custom attribute of an element javascript"

2

set attribute in javascript

//Fetch id from html
var a = document.getElementById("id");

//variable.setAttribute("Attributes","Properties:Values")
a.setAttribute("style", "visibility:hidden;");
Posted by: Guest on May-22-2021
0

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>
Posted by: Guest on December-21-2021

Code answers related to "set custom attribute of an element javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language