jQuery hover and class selector

后端 未结 10 1700
半阙折子戏
半阙折子戏 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:29

    I would suggest not to use JavaScript for this kind of simple interaction. CSS is capable of doing it (even in Internet Explorer 6) and it will be much more responsive than doing it with JavaScript.

    You can use the ":hover" CSS pseudo-class but in order to make it work with Internet Explorer 6, you must use it on an "a" element.

    .menuItem
    {
        display: inline;
        background-color: #000;
    
        /* width and height should not work on inline elements */
        /* if this works, your browser is doing the rendering  */
        /* in quirks mode which will not be compatible with    */
        /* other browsers - but this will not work on touch mobile devices like android */
    
    }
    .menuItem a:hover 
    {
        background-color:#F00;
    }
    

提交回复
热议问题