Reputation: 38654
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?
Upvotes: 13
Views: 23459
Reputation: 344
In dojo, you would do it like this:
dojo.style("div1", "height", "300px");
Having the units on the height is important, as mentioned in the docs.
Upvotes: -1
Reputation: 38378
Here is how it might look with jQuery:
<div id="div1" style="width:600;height:600;border:solid 1px"></div>
<a href="#">Change height to 300</a>
<script type="text/javascript">
$(function() {
$('a').click(function() {
$('#div1').css('height', '400px');
return false;
});
});
</script>
Upvotes: 2
Reputation: 3123
Judging by his example code he is using the dojo framework. Changing height in dojo would be done with something similiar to the following:
dojo.style("div1", "height", 300);
http://api.dojotoolkit.org/jsdoc/dojo/1.2/dojo.style
Upvotes: 7
Reputation: 348
Just replace your comment with:
node.style.height = height;
Oh, not sure if just passing 300 to your function will make it work, perhaps you'll have to pass "300px" like suggested in the other posts...
Upvotes: 1
Reputation: 116167
document.getElementById("div1").style.height = height + "px";
Upvotes: 5
Reputation: 12195
<script type="text/javascript">
function changeHeight(height)
{
document.getElementById("div1").style.height = height + "px";
}
</script>
Upvotes: 26