Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
How to addclass and removeclass in jquery
3093 Views
Note 
addClass() and removeClass() functions are used to add and remove the class dynamically to the elements.
Example : 1 when you click first element class added to the second element.When you click third element the class removed from the second element.
Example: 1
<html>

<head>
    <title>HTML-JQuery</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $(".one").click(function () {
                $(".two").addClass('selected');
            });
            $(".three").click(function () {
                $(".two").removeClass('selected');
            });
        });
    </script>
    <style>
        .selected {
            color: red;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <div class="one">click here to add class name 'selected' with next element</div>
    <div class="two">After click the element the selected class css applied here</div>
    <div class="three">click here to remove class name 'selected' from the above element</div>
</body>

</html>
Example: 1 Demo 
Best Lessons of "JQuery Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details