Skip to content

Instantly share code, notes, and snippets.

Created March 12, 2014 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/9515376 to your computer and use it in GitHub Desktop.
Save anonymous/9515376 to your computer and use it in GitHub Desktop.
#box {
width: 200px;
height: 200px;
padding: 10px;
margin: 5px;
border: 1px solid black;
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Welcome to JS Bin</title>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head>
<body>
<div id="box">
</div>
</body>
</html>
var $box = $("#box");
console.clear();
console.log($box.width()); // 200
console.log($box.innerWidth()); // 220
console.log($box.outerWidth()); // 222
console.log($box.outerWidth(true)); // 232
console.log("");
var box = document.getElementById("box");
console.log(box.clientWidth); // 220
console.log(box.offsetWidth); // 222
console.log(box.getBoundingClientRect().width); // 222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment