Get the App
SLTechnology News&Howtos  ›  Development  › 

How to delete css styles using jquery

Shulou Source: shulou.com Published: 2022-06-02 00:53:29 10月03日 Update

How to delete the css style using jquery, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Delete method: 1, use removeClass () or toggleClass () to remove the specified CSS class, syntax "removeClass (" class name ")" or "toggleClass (" class name ")"; 2, use removeAttr () to remove id, class or style attributes.

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

Jquery method to delete css style:

1. Use removeClass () or toggleClass () to remove the specified CSS class

RemoveClass ()-remove the CSS class

$("# target"). RemoveClass ("oldClass"); / / # target refers to the ID//oldClass of the element that needs to be removed from the CSS class, and refers to the name of the CSS class

ToggleClass ()-add or remove CSS classes

If the CSS class already exists, it will be removed; conversely, if the CSS class does not exist, it will be added.

$("# target"). ToggleClass ("newClass") / / if the element whose ID is "target" has already defined the CSS style, it will be removed; / / conversely, the CSS class "newClass" will be assigned to the ID.

2. Use removeAttr () to remove id, class or style attributes

$(document) .ready (function () {$("button") .click (function () {$("p"). RemoveAttr ("style");}); this is a title and this is a paragraph.

This is another paragraph.

Delete the style attribute of all p elements

Jquery is what jquery is a simple and fast JavaScript library, it has a unique chain syntax and short and clear multi-function interface, efficient and flexible css selector, and can be extended to CSS selector, with convenient plug-in extension mechanism and rich plug-ins, after Prototype is another excellent JavaScript code base, can be used to simplify event processing, HTML document traversal, Ajax interaction and animation, in order to quickly develop the website.

This is the answer to the question about how to delete the css style when using jquery. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Tags: Styles elements attributes methods this is questions plug-ins more paragraphs class names syntax help solutions selection excellent convenient easy unique concise easy to do Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple Linux Xiaomi macOS