JQUERY: APPEND A CLASS ON HOVER OF A DIV AND REMOVE WHEN NOT HOVER

Samuel Fernandes

Total Post:159

Points:1117
Posted by  Samuel Fernandes
JQuery 
 1736  View(s)
Ratings:
Rate this:
Hi Expert!

I want to append a class to a div on hover of that div and remove that class when its not on hover. And when I hover on another div, again this class should be 

appended and removed when its not on hover. Someone say me how to do it in jquery......

Thanks in advance!

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Jquery: Append a Class on hover of a div and remove when not hover

    Hi Samuel!

    replace addClass and removeClass functions in jquery as following 

    $(document).ready(function() {     
        $('#secID, #thID').hover(function(){     
            $('#oneID').addClass('red');    
        },     
        function(){    
            $('#oneID').removeClass('red');     
        });
    });  

    I hope it is useful to you

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!