jQuery hover and class selector

后端 未结 10 1772
半阙折子戏
半阙折子戏 2020-12-10 00:56

I wan\'t to change the background color of a div dynamicly using the following HTML, CSS and javascript. HTML:


      
      
10条回答
  •  误落风尘
    2020-12-10 01:22

    test.html

    
    
    
        
            jQuery Test
            
            
            
        
        
            
        
    
    

    test.css

    .menuItem
    {
    
        display: inline;
        height: 30px;
        width: 100px;
        background-color: #000;
    
    }
    

    test.js

    $( function(){
    
        $('.menuItem').hover( function(){
    
            $(this).css('background-color', '#F00');
    
        },
        function(){
    
            $(this).css('background-color', '#000');
    
        });
    
    });
    

    Works :-)

提交回复
热议问题