Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery adding class

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 166
    Comment on it

    We can dynamically add class to the html using the jQuery.

    It is used when we are adding html dynamically or when at an event we want that css to be called.

    We can add the css class simply
     

    $("button").click(function(){
    
    $("h1,p,a,span").addClass("red")
    
    });

    We can also remove the class by simply using function.
     

    $(".add").click(function(){
    
    $("h1, p, a, span").removeClass("grey")
    
    });

    Instead of giving the button we can also give the id or class like in remove function.

    We can also change the event like for click we can use keyUp.

 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: