CSS/JS Solution: On hover of child element, change parent div

后端 未结 5 726
半阙折子戏
半阙折子戏 2021-01-16 04:56

I know CSS is \"cascading\", but in this case I want the effect to ascend. I\'m open for either a JS or CSS solution, but honestly I\'d prefer the solution with the least a

5条回答
  •  悲哀的现实
    2021-01-16 05:49

    A without jquery solution:

    onload = function()
    {
      var links = document.getElementsByTagName('a');
      for (var i = 0; i < links.length; ++i)
      {
        if (links[i].className == 'letter')
        {
          links[i].onmouseover = function() {
            document.getElementById('word').style.backgroundColor="#0000FF";
          };
          links[i].onmouseout = function() {
            document.getElementById('word').style.backgroundColor="#FFFFFF";
          };
        }
      }
    }
    

提交回复
热议问题