Remove css style dynamically in jquery

remove css style dynamically in jquery
Here we will see how to remove css style of the element in jquery. In web applications we need to remove css style dynamically to give user friendly ui effects and for that we can use .removeClass() function in jquery. Here we will see example of div in which when user clicks on link it will change color of div by applying css style dynamically.

Example to remove css style dynamically

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <title>Remove css style dynamically</title>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#clickme").click(function () {
                $("#dynamic-style").removeClass("myStyle");
            });
        });
    </script>
    <style type="text/css">
        .myStyle
        {
            width: 500px;
            height: 300px;
            background-color: wheat;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <a href="#" id="clickme">Change</a>
    <div id="dynamic-style" class="myStyle">
        Click change to change color.
    </div>
    </form>
</body>
</html>

Add css style dynamically in jquery

add css style dynamically injquery

In this post we will see how to add css style to element in jquery. In web applications we need to add css style dynamically to give user friendly ui effects and for that we can use .addClass() function in jquery. Here we will see example of div in which when user clicks on link it will change color of div by applying css style dynamically.

Example to add css style dynamically

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <title>Add css style dynamically</title>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#clickme").click(function () {
                $("#dynamic-style").addClass("newStyle");
            });
        });
    </script>
    <style type="text/css">
        .newStyle
        {
            width: 500px;
            height: 300px;
            background-color: wheat;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <a href="#" id="clickme">Change</a>
    <div id="dynamic-style">
        Click change to change color.
    </div>
    </form>
</body>
</html>