How can I change one value in style attribute with JavaScript?

David.Chu.ca picture David.Chu.ca · Mar 25, 2009 · Viewed 17.7k times · Source

I have a div defined with a style attribute:

<div id="div1" style="width:600;height:600;border:solid 1px"></div>

How can I change the height of the div with JavaScript?

Answer

Sebastian Celis picture Sebastian Celis · Mar 25, 2009
<script type="text/javascript">
function changeHeight(height)
{
   document.getElementById("div1").style.height = height + "px";
}
</script>