views:

143

answers:

2

Hi all

Any ideas how I would go about writing a javascript method to insert an attribute to a tag

eg. I have

<input id='in1' value='Submit' type='submit'/>

and I want to insert an attribute name

<input id='in1' name='submit_content' value='Submit' type='submit'/>

Thanks

+7  A: 

Try this:

document.getElementById("in1").setAttribute("name", "submit_content");
Gumbo
Thats perfect, thanks a lot
mark
It’s actually `setAttribute` instead of `addAttribute`. I fixed that.
Gumbo
+2  A: 
document.getElementById("in1").setAttribute("name", "submit_content");

or using jQuery:

$("#in1").attr("name", "submit_content");
kim3er
thats perfect thanks a lot
mark