Home>Article>Web Front-end> How to clear inline style attributes in jquery
Two clearing methods: 1. Use removeAttr() to remove the style attribute from the matching element. You only need to set the parameter value of the function to "style". The syntax is "specified element.removeAttr(" style")". 2. Use attr() to set the value of the style attribute to empty. You only need to set the value of the first parameter of the function to "style" and the value of the second parameter to an empty string. The syntax "specifies Element.attr("style","")".
The operating environment of this tutorial: windows7 system, jquery3.6.0 version, Dell G3 computer.
The inline style attributes of HTML are written in the style attribute.
In other words, by controlling the value of the style attribute, you can control the inline style.
Therefore, using query to clear the inline style attribute is to remove the style attribute, or set the value of the style attribute to a null character.
Two methods for jquery to clear CSS inline style attributes
Method 1: Use removeAttr() to remove the style attribute
removeAttr() can remove the specified attribute from all matching elements.
$(selector).removeAttr(attribute)
attribute: required. Specifies the attributes to remove from the specified element.
Just set the attribute parameter to style.
Method 2: Use attr() to set the value of the style attribute to empty
attr() method can be set to be Select the attributes and values of the element.
$(selector).attr(attribute,value)
Parameter | Description |
---|---|
attribute | Specification The name of the property. |
value | Specifies the value of the attribute. |
Just set the first parameter of the function tostyle
, and the second parameter to the empty string''
is enough.
[Recommended learning:jQuery video tutorial,web front-end video】
The above is the detailed content of How to clear inline style attributes in jquery. For more information, please follow other related articles on the PHP Chinese website!