...

View Full Version : Get border and padding width of cell



StevenTNorris
03-23-2012, 05:31 PM
Hello all,
I need to get the border and internal padding width of a cell of a table. I plan to subtract these values from the offsetWidth to get the content width, and use that to set the style.width of another cell. Unfortunately, I can't find a tried-and-true way to get the border and padding width. Anyone got an idea?

c1lonewolf
03-23-2012, 06:42 PM
http://www.javascriptkit.com/domref/tableproperties.shtml

StevenTNorris
03-23-2012, 07:19 PM
Those are properties for a table. I need properties for a table cell.

DaveyErwin
03-23-2012, 08:06 PM
Maybe you can use this ?
Subtract them to get border plus padding.
Can't swear that it works everywhere.

<style>
table { border-width: 7px;
border-style: outset; }
td { border-width: 5px;
border-style: outset;
padding:5px}
p { border-width: thick;
border-style: solid; }
</style>
<script>


function getOuterDimensions(el) {
return [el.offsetHeight, el.offsetWidth];
};

function getInnerDimensions(el) {
return [el.clientHeight, el.clientWidth];
};
function init(){
var elSpan = document.getElementById("elSpan");
var elTd = document.getElementById("elTd");
alert(getOuterDimensions(elTd))
alert(getInnerDimensions(elTd))
alert(getOuterDimensions(elSpan))
}
</script>
<body onload="init()">
<table>
<tr>
<td id="elTd">
<span id="elSpan">hello</span>
</td>
</tr>
</table>

</body>

DaveyErwin
03-23-2012, 09:33 PM
Hello all,
I need to get the border and internal padding width of a cell of a table. I plan to subtract these values from the offsetWidth to get the content width,

why not just get the content width ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum