Skip to content Skip to sidebar Skip to footer

Border And Padding Width Javascript

UPDATE: Edited javascript code. It's only slightly off now in some columns. Maybe a pixel or two. Not sure why. I need to get the border and internal padding width of a cell of a t

Solution 1:

If you have this table

<table><tr><tdid="my"style="padding: 5px; border:3px;"></td></tr></table>

you can do

var padding = document.getElementById('my').style.padding;
 var border = document.getElementById('my').style.border;

fiddle here http://jsfiddle.net/7TmXm/

Solution 2:

Try this:

var theDiv = $("#theDiv");
var totalWidth = theDiv.width();
totalWidth += parseInt(theDiv.css("padding-left"), 10) + parseInt(theDiv.css("padding-right"), 10); //Total Padding Width
totalWidth += parseInt(theDiv.css("margin-left"), 10) + parseInt(theDiv.css("margin-right"), 10); //Total Margin Width
totalWidth += parseInt(theDiv.css("borderLeftWidth"), 10) + parseInt(theDiv.css("borderRightWidth"), 10); //Total Border Width

Borrowed from this answer.

Post a Comment for "Border And Padding Width Javascript"