Home >Web Front-end >JS Tutorial >How to delete css style using jq
Deletion method: 1. Use removeClass() or toggleClass() to remove the specified CSS class, the syntax is "removeClass("class name")" or "toggleClass("class name")"; 2. Use removeAttr ()Remove id, class or style attributes.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
How to delete css style in jquery:
1. Use removeClass() or toggleClass() to remove the specified CSS class
removeClass() - Remove CSS class
$("#target").removeClass("oldClass"); //#target 指的是需要移除CSS类的元素的ID //oldClass 指的是CSS类的名称
toggleClass() - Add or remove CSS class
If the CSS class already exists, it will is removed; instead, if the CSS class does not exist, it will be added.
$("#target").toggleClass("newClass") //如果ID为“target”的元素已经定义了CSS样式,它将被移除; //反之,CSS类”newClass“将被赋给该ID。
2. Use removeAttr() to remove id, class or style attributes
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").removeAttr("style"); }); }); </script> </head> <body> <h1>这是一个标题</h1> <p style="font-size:120%;color:red">这是一个段落。</p> <p>这是另一个段落。</p> <button>删除所有 p 元素的 style 属性</button> </body> </html>
(Learning video sharing: css video tutorial)
The above is the detailed content of How to delete css style using jq. For more information, please follow other related articles on the PHP Chinese website!