Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to add attribute to existing tag using javascript

I am curious if it is possible using javascript to take an existing html statement like

<input id="name">

and transform it to

<input id="name" asdf="fdsa">
like image 691
SLIM Avatar asked Dec 26 '22 02:12

SLIM


1 Answers

Yes , try this:

document.getElementById("name").setAttribute("user-attr","Hello")

Pure Vanilla Javascript!

like image 78
Ivan Chernykh Avatar answered Jan 14 '23 02:01

Ivan Chernykh