width()
- returns the width of an element.
innerWidth()
- returns the width of an element includes padding.
outerWidth()
- returns the width of an element includes padding and border.
outerWidth(true) - returns the width of an element includes padding, border and margin.
height()
- returns the height of an element.
innerHeight()
- returns the height of an element includes padding.
outerHeight()
- returns the height of an element includes padding and border.
outerHeight(true) - returns the height of an element includes padding, border and margin.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>/*from w ww .j a v a 2 s .c o m*/ <script> $(document).ready(function(){ $("button").click(function(){ let txt = ""; txt += "Width of div: " + $("#div1").width() + "</br>"; txt += "Inner width of div: " + $("#div1").innerWidth() + "</br>"; txt += "Outer width of div: " + $("#div1").outerWidth() + "</br>"; txt += "Outer width of div (margin included): " + $("#div1").outerWidth(true) + "</br>" + "</br>"; txt += "Height of div: " + $("#div1").height() + "</br>"; txt += "Inner height of div: " + $("#div1").innerHeight() + "</br>"; txt += "Outer height of div: " + $("#div1").outerHeight() + "</br>"; txt += "Outer height of div (margin included): " + $("#div1").outerHeight(true) + "</br>"; $("#div1").html(txt); }); }); </script> </head> <body> <div id="div1" style="height:180px;width:300px;padding:10px;margin:4px;background-color:lightblue;"></div> <br> <button>Display dimensions of div</button> </body> </html>