Home > Web Front-end > JS Tutorial > body text

How to remove css attributes of elements in jquery

WBOY
Release: 2021-12-08 17:47:09
Original
4570 people have browsed it

Jquery method to remove the css attribute of an element: 1. Use the "$(element)" statement to obtain the specified element object; 2. Use the css() method to remove the css attribute of the element. The syntax is "element object .css("property name","");".

How to remove css attributes of elements in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to remove the css attribute of an element in jquery

How to remove the css attribute in jquery? If a certain CSS style attribute is added to the dom element of the html, we cannot directly remove these added attributes using jquery, but we can use the style override method to remove the set attributes and restore them to the default style. The following is Let's see how to deal with it.

Since we are using jquery for processing, we will first introduce the jquery plug-in file.

How to remove css attributes of elements in jquery

On the html, we create a div with the style my_class and a button to trigger the deletion of the css attribute value.

How to remove css attributes of elements in jquery

Coupled with the corresponding style code, here we mainly focus on the set height and color attribute values.

How to remove css attributes of elements in jquery

#In the button click event function, we can use jquery’s css method to set the style attributes. For example, if we set the height value here to auto, we can restore the value of the height attribute set in the original style to the default value.

How to remove css attributes of elements in jquery

Let’s take a look at the page first. Now the height of the div is 300px. Let’s click the button below.

How to remove css attributes of elements in jquery

After clicking, you can see that the height value set by the original style is no longer effective and has been overwritten to the default value of auto, which is equivalent to The original attribute value is deleted.

How to remove css attributes of elements in jquery

It should be noted that different style attribute values ​​have different default values, such as color, the default value is inherit,

How to remove css attributes of elements in jquery

Refresh the page and click the button again. In addition to the height returning to the default value, the text color also returns to black font, which is equivalent to not setting the color style attribute.

How to remove css attributes of elements in jquery

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How to remove css attributes of elements in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!