Get CSS styles in jquery
CSS (name): Access the style attribute of the First Matching Element
CSS (name, value): set the value of a style attribute among all matching elements.
CSS (properties): sets a "name/value pair" object as the style attribute of all matching elements.
CSS (name, function (index, value): In all matching elements, set the value of a style attribute.
Bytes -------------------------------------------------------------------------------------
Obtain the style value in Javascript
Function CSS (OBJ, ATTR, value ){
Switch (arguments. Length ){
Case 2:
If (typeof arguments [1] = "object") {// set attributes in batches
For (var I in ATTR) obj. Style [I] = ATTR [I]
}
Else {// read the attribute value
Return obj. currentstyle? OBJ. currentstyle [ATTR]: getcomputedstyle (OBJ, null) [ATTR]
}
Break;
Case 3:
// Set attributes
OBJ. Style [ATTR] = value;
Break;
Default:
Return "";
}
}
This method also achieves jquery's effect.
Bytes ---------------------------------------------------------------------------------------
Jquery includes addclass, removeclass, and toggleclass.
Addclass (class): add the specified class name for each matching element.
Removeclass (class): deletes all or specified classes from all matching elements.
Toggleclass (class): deletes (ADDs) a class if it exists (does not exist ).
Bytes ---------------------------------------------------------------------------------------
Function hasclass (OBJ, CLS ){
Return obj. classname. Match (New Regexp ('(\ s | ^)' + CLS + '(\ s | $ )'));
}
Function addclass (OBJ, CLS ){
If (! This. hasclass (OBJ, CLS) obj. classname + = "" + CLS;
}
Function removeclass (OBJ, CLS ){
If (hasclass (OBJ, CLS )){
VaR Reg = new Regexp ('(\ s | ^)' + CLS + '(\ s | $ )');
OBJ. classname = obj. classname. Replace (Reg ,'');
}
}
This method also achieves jquery's effect.