Skip to content

Instantly share code, notes, and snippets.

@ultim8k
Created January 11, 2014 11:43
Show Gist options
  • Save ultim8k/8369942 to your computer and use it in GitHub Desktop.
Save ultim8k/8369942 to your computer and use it in GitHub Desktop.
Get total width of a dom element (width + padding + margin + borders)
function getTotalWidth(el){
var width = el.width();
var padding = parseInt(el.css("padding-left"), 10) + parseInt(el.css("padding-right"), 10);
var margin = parseInt(el.css("margin-left"), 10) + parseInt(el.css("margin-right"), 10);
var border = parseInt(el.css("borderLeftWidth"), 10) + parseInt(el.css("borderRightWidth"), 10);
return width + padding + margin + border;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment