Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to add/remove class to an element on keyup event with jQuery?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 3.09k
    Comment on it

    We can add or remove a class to an element very easily by using addClass() and removeClass() methods. To do this on keyup event of a textbox we just need call these functions when we bind keyup event to textbox.

    Example:

    <input id="search-box" type="text" placeholder="search city...."/>
    <input type="button" id="search-submit" value="Search" />
    
    $(function(){
    
    $("#search-box").on("keyup", function(){
                   if($("#search-box").val() == ""){
                    $('#search-submit').addClass("not-active-search");
                   } else {
                    $('#search-submit').removeClass("not-active-search");
                   }        
                });
    });
    

    Hope this will help you :)

 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: