Tuesday, 10 April 2012

How to use javascript to change an element's attributes

document.getElementById('id').setAttribute("style","position:absolute;left:10px");


This method is useful if you have a lot of properties to add, but it can overwrite the other style attributes that you may have already set.


An alternative method is:

document.getElementById('id').style.width = "500px";

No comments:

Post a Comment

Please enter your message here...