Justin John
Justin John

Reputation: 9635

How to remove all CSS property inside a class, but don't remove class using jQuery

Remove all CSS property in class by don't removing class using jQuery

For example :

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

    //To

    .ui-widget {
    }

Upvotes: 4

Views: 5180

Answers (2)

PhillipKregg
PhillipKregg

Reputation: 9358

Yup, what Trott said.

Use something like this:

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

That script causes the class to toggle when you click on a paragraph. You can change the paragraph to be anything and it doesn't need to be a click function either. The line with toggleClass is what's important there.

The toggleClass function will let you go back and forth between style and no-style.

Upvotes: 0

Trott
Trott

Reputation: 70163

Instead of trying to alter style properties, I would create two separate classes and use jQuery to toggle the classes of HTML elements. That would seem to be more straightforward.

Upvotes: 3

Related Questions