Skip to content Skip to sidebar Skip to footer

How To Add A New Attribute To A Tag

In some HTML, I saw the input tag has the attribute verify. How to add it to the input tag? I tried the code a

Solution 1:

If you mean to say that the html input element has a [verify] attribute, then you can access the attribute via getAttribute():

HTML:
<input id="test" verify="test" />
JS:
document.getElementById('test').getAttribute('verify'); //test

Solution 2:

Adding an attribute with pure Javascript is done via setAttribute

document.getElementById("test").setAttribute("verify","verified");

And to read it:

document.getElementById("test").getAttribute("verify")

Post a Comment for "How To Add A New Attribute To A Tag"