How to remove all CSS properties inside a class but not delete the class using jQuery

Remove all CSS properties in a class without deleting the class using jQuery

For instance:

.ui-widget { font-family: Verdana,Arial,sans-serif/*{ffDefault}*/; font-size: 1.1em/*{fsDefault}*/; left: 350px !important; top: 160px !important; } //To .ui-widget { } 
+4
source share
2 answers

Instead of trying to change the style properties, I would create two separate classes and use jQuery to switch the classes of HTML elements. That would be simpler.

+3
source

Yes, what Trott said.

Use something like this:

 <script> $("p").click(function () { $(this).toggleClass("removeStyle"); }); </script> 

What the script makes the class switch when you click on the paragraph. You can change the paragraph to anything, and it should not be a click function either. What is important where toggleClass is located.

The toggleClass function allows you to move between style and style.

0
source

Source: https://habr.com/ru/post/1383562/


All Articles