Jump to content

DOM access


george

Recommended Posts

I have a function called by an event. On arrival to my function I want to get and set the width value of a div object. But I can’t seem to get it, or set it. Here is what I have tried using "coverup" as my object ID:

<style>#coverup { position:absolute; top:0; left:0; width:120px; height:auto; }</style><script>document.getElementById('coverup').width </script><html>	<div id="coverup"></div></html>

I think my problem is not knowing the proper DOM script to get the value of the width of the object ‘coverup’. Thanks

Link to comment
Share on other sites

use scrollWidth to get width of element including padding, but not including any border width.use offsetWidth to get width of element including padding, and any border width.To assign a new width with document.getElementById('coverup').style.width="240px";If you retrieve the value using whatever method and assign the value to a variable, remember to add 'px' unit text at end.var currentwidth = document.getElementById('coverup').scrollWidth;document.getElementById('coverup').style.width=(currentwidth+120)+"px";

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...