Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get element height and width to match exactly

Status
Not open for further replies.

tas2826

Programmer
Jul 6, 2005
26
US
Is there a way to get elements of different types to match exactly in size? For example, I have a textarea and a div. I want to make the div height and width match that of the text area exactly when the page loads. I have the following javascript called by onLoad().

Code:
document.getElementById('aDiv').style.height = document.getElementById('aTextarea').clientHeight;

document.getElementById('aDiv').style.width = document.getElementById('aTextarea').clientWidth;

However, when the page loads the div ends up being a little bit wider than the textarea. Am I using the right attributes?

Thanks in advance.

Troy
 
In a perfect world, yes. In the real world, you will never manage to do this cross-browser and cross-OS without a lot of hard work.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
In a perfect world, yes. In the real world, you will never manage to do this cross-browser and cross-OS without a lot of hard work.

That is the realization I was coming to. Now if I can just convince the QA folks. ;)

Thanks,

Troy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top