[Web front-end | jQuery] jQuery style operation

jQuery style manipulation

1: Method of operating css

1.1: The parameter only writes the attribute name, then the attribute value is returned
$(this).css("color");
1.2: Operation, modify the style, the parameter is the attribute name, the attribute value, separated by commas, is to set a group of styles, the attribute must be quoted, if the value is a number, it is not necessary to follow the unit and quotes
$(this).css("color","red");
1.3: Modify multiple styles, the parameters can be in the form of objects, the attribute name and attribute value are separated by colons, and the attribute does not need to be quoted.
$(this).css({
    
    
    "color": "white",
})

Compound attributes: camel case nomenclature

2: Set the class name method

2.1: Add class
$("div").addClass("current");
2.2: Delete class
$("div").removeClass("current");
2.1: Switching class
toggleClass("");  //有则去,无则加

The difference between class operation and class N ame The difference between class operation and className Class operation for the C L A S S N A m E region not

The className in native JS will override the original class name in the element.
The class operation in jQuery only operates on the specified class and does not affect the original class name

Guess you like

Origin blog.csdn.net/qq_43490212/article/details/111754301