Insert multiple attributes into html tag using JavaScript and not between tags

Posted by WilliamK on Stack Overflow See other posts from Stack Overflow or by WilliamK
Published on 2012-12-06T04:49:40Z Indexed on 2012/12/06 5:03 UTC
Read the original article Hit count: 122

Filed under:

From a previous quest we asked about inserting a new attribute into a html tag and the code below does the job nicely, but how should it be coded to add multiple attributes, for example changing..

<body bgcolor="#DDDDDD">

to...

<body bgcolor="#DDDDDD" topmargin="0" leftmargin="0"> 

The code that works for a single attribute is...

document.getElementsByTagName("body")[0].setAttribute("id", "something");

How to modify this for inserting multiple attributes?

© Stack Overflow or respective owner

Related posts about JavaScript