There are two ways to get and set the width and height of a div: using the dimension function or using the css method
Get width and height
1. Dimension function: height() gets height, width() gets width
2. Obtain div width and height by CSS: obtain height by css("height") and width by css("width")
Difference: the value obtained by dimension function is integer, while the value obtained by css is string with px
Two pop-up values are:
Div width: 100;div height: 100
Div width: 100px;div height: 100px
Set width and height
The first method: set height(10) width(10) using the dimension function
The second method: use css function to set
css({"width":"10px","height":"10px"}) / / when using css to set multiple attributes, separate attributes in braces with commas
css("width","10px") / / when you use css to set a single property, separate the property name and property value with commas (you don't need to put them in braces)
The third method: use the animate setting (the specific usage is in the next article)
. animate({width:"10px",height:"10px"},4000); / / the difference between using animate and css parameters is that the attribute name of the animate parameter does not need to be enclosed in quotation marks
html part code: