In jquery, you can use the removeAttr() method to remove the style attribute. The function of this method is to remove the specified attribute from the selected element. You only need to set the parameter of the method to "style" That's it; the syntax is "$(selector).removeAttr("style")".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
The style attribute is the core attribute of HTML and is used to specify inline style for elements. The
style attribute will override other global styles, such as those defined in the
So how to remove the style attribute using jquery
In jquery, you can use the removeAttr() method to remove the style attribute.
removeAttr() method is used to remove attributes from selected elements.
Syntax:
$(selector).removeAttr(attribute)
attribute: required. Specifies the attributes to remove from the specified element.
Example: Remove the style attribute of the first p element
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("button").click(function() { $("p:first").removeAttr("style"); }); }); </script> </head> <body> <h1>这是一个大标题</h1> <p style="font-size: 120%;color: blue;background-color: yellow;">这是一个段落。</p> <p style="font-size: 120%;color: blue;background-color: yellow;">这是另一个段落。</p> <button>移除第一个 p 元素的style属性</button> </body> </html>
[Recommended learning: jQuery video tutorial, web Front-End Development Video】
The above is the detailed content of How to remove style attribute in jquery. For more information, please follow other related articles on the PHP Chinese website!