Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use addClass() in jquery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 421
    Comment on it

    The addclass() method is used to add one or more class name to the selected element.

    This method is used only to add one or more class names to the class attributes not to remove the existing class attributes.

    Syntax :

    $(selector).addClass(classname,function(index,oldclass))   
    

    Example :

    <!DOCTYPE html>  
    <html>  
    <head>  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
    <script>  
    $(document).ready(function(){  
        $("button").click(function(){  
            $("p:first").addClass("intro");  
        });  
    });  
    </script>  
    <style>  
    .intro {  
        font-size: 200%;  
        color: red;  
    }  
    </style>  
    </head>  
    <body>  
    <h1>This is a heading</h1>  
    <p>This is a paragraph.</p>  
    <p>This is another paragraph.</p>  
    <button>Add a class name to the first p element</button>  
    </body>  
    </html> 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: