JQuery obtains the outerWidth and outerHeight Methods containing margin.
This article mainly introduces jQuery's method of obtaining outerWidth and outerHeight containing margin, which involves the usage skills of outerWidth and outerHeight in jQuery. It has some reference value. If you need it, you can refer
This example describes how jQuery obtains outerWidth and outerHeight containing margin. Share it with you for your reference. The details are as follows:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<! DOCTYPE html> <Html> <Head> <Script src = "js/jquery. min. js"> </Script> <Script> $ (Document). ready (function (){ $ ("Button"). click (function (){ Var txt = ""; Txt + = "Width of div:" + $ ("# div1"). width () + "</br> "; Txt + = "Height of div:" + $ ("# div1"). height () + "</br> "; Txt + = "Outer width of div (margin encoded DED):" + $ ("# div1"). outerWidth (true) + "</br> "; Txt + = "Outer height of div (margin included):" + $ ("# div1"). outerHeight (true ); $ ("# Div1" ).html (txt ); }); }); </Script> </Head> <Body> <Div id = "div1" style = "height: 100px; width: 300px; padding: 10px; margin: 3px; border: 1px solid blue; background-color: lightblue;"> </Div> <Br> <Button> Display dimensions of div </button> <P> outerWidth (true)-returns the width of an element (bounded des padding, border, and margin). </p> <P> outerHeight (true)-returns the height of an element (partition des padding, border, and margin). </p> </Body> </Html> |
I hope this article will help you with jQuery programming.