Answers for "attribute javascript"

15

javascript get attribute

//HTML
//<div id="elem" data-id="4hJ3s"></div>

var elem = document.getElementById("elem");
elem.getAttribute("data-id"); // "4hJ3s"
Posted by: Guest on May-20-2020
2

javascript element read attribute

document.getElementById('id1').getAttribute('attribute');
Posted by: Guest on July-15-2020
2

js getattribute

const link = document.querySelector('a');

console.log(link.getAttribute('href'));
Posted by: Guest on July-19-2020
0

attribute in javascript

elem.hasAttribute(name) //checks for existence.
elem.getAttribute(name) //gets the value.
elem.setAttribute(name, value) //sets the value.
elem.removeAttribute(name) //removes the attribute.
elem.attributes //collection of all attributes.
Posted by: Guest on May-18-2021
14

set attribute javascript

Element.setAttribute(name, value);
Posted by: Guest on March-02-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language