jQuery gets common attributes

Get common attributes

Although we can get almost all information about the element by getting attributes, characteristics and CSS styles, but pay attention to the following experiment:

    get object width   
test text

We want to get the test layer For the width, use the attr method to get the "element attribute" as undefined, because no width is added to the div. Although the value of the style attribute can be obtained using the css() method, the results returned in different browsers are different. IE6 returns auto, while FF returns the correct value but with "px" behind it. So jQuery provides the width() method, which returns the correct value without px.

In response to the above problem, jQuery provides methods for obtaining and setting commonly used attributes. For example, width() allows users to obtain the width of an element, while width(val) is used to set the width of an element.

The following methods can be used to obtain the common attribute values of elements:

HeightAndWidth.jpg

##1. Width and height are related to Height and Width

Regarding the function to obtain the length and width, it is necessary to distinguish the differences between the three functions "inner", "outer" and height/width:

division.jpg

outerWidth can accept a bool value parameter to indicate whether to calculate the margin value.

I believe this picture clearly shows the scope requested by each function. The picture uses width as an example, and the functions of height are the same.

2. Position-related Positioning

In addition, in some scripts involving pop-up objects, it is often necessary to dynamically obtain the pop-up coordinates and set the element's Location.

However, many methods of calculating position have browser compatibility issues. jQuery provides us with various position-related functions:

Positioning.jpg

Continuing Learning
||

这是要显示粗体的节奏


submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!