We can use GetAttribute and setattribute in JavaScript to manipulate element attributes of elements. In JQuery, you are provided with a attr () wrapper set function that allows you to manipulate the attributes of all the elements in the wrapper set:
Although we can use REMOVEATTR (name) to delete element properties, the corresponding DOM attribute is not deleted, only the value of the DOM property is affected. For example, removing the readonly element attribute of an INPUT element causes the corresponding DOM property to become False ( That is, input becomes an editable state).
? modifying CSS classes and styles
The following table is a way to modify the CSS class-related JQuery method:
<!doctype html>
"zh"
>
<meata charset=
"utf-8"
/>
<title>get object width</title>
<script src=
"jquery-1.11.2.min.js"
></script>
<script>
$(
function
() {
alert(
"attr(\"width\"):"
+ $(
"#testDiv"
).attr(
"width"
));
//undifined
alert(
"css(\"width\"):"
+ $(
"#testDiv"
).css(
"width"
));
//auto(ie6) 或 1264px(ff)
alert(
"width():"
+ $(
"#testDiv"
).width());
//正确的数值 1264
alert(
"style.width:"
+ $(
"#testDiv"
)[0].style.width);
//空值
})
</script>
<body>
<div id=
"testDiv"
>test text</div>
</body>
We want to get the width of the test layer and use the attr method to get "element attribute" to undefined because it does not add width to the div. While using the CSS () method, although the value of the style property can be obtained, but the results returned in different browsers are different, IE6 returns auto, while the FF returns the correct value but with "px" behind it. So jQuery provides the width () method, which returns the correct value without PX.
For the above question, JQuery provides a way to get and set the common properties, such as width () the user gets the widths of the elements, and width (val) is used to set the element width.
Outerwidth can accept a bool value parameter to indicate whether the margin value is calculated.
2. Location-related positioning
jquery operation properties and style explained