Reputation: 11
<input id="test" value="123" name ="test" verify="NOTNULL">
In some HTML, I saw the input
tag has the attribute verify
. How to add it to the input tag?
I tried the code
alert(document.getElementById("test").verify)
the result is undefined
.
How do I add a new attribute to the element?
Upvotes: 1
Views: 2018
Reputation: 63966
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")
Upvotes: 1
Reputation: 179046
If you mean to say that the html input element has a [verify]
attribute, then you can access the attribute via getAttribute()
:
<input id="test" verify="test" />
JS:
document.getElementById('test').getAttribute('verify'); //test
Upvotes: 5