How to write a:hover in inline CSS?

后端 未结 23 2552
孤城傲影
孤城傲影 2020-11-21 23:15

I have a case where I must write inline CSS code, and I want to apply a hover style on an anchor.

How can I use a:hover in inline CSS inside the HTML st

23条回答
  •  无人共我
    2020-11-21 23:43

    This is the best code example:

    Moderator Suggestion: Keep your separation of concerns.

    HTML

    JS

    const libLink = document.getElementsByClassName("lib-link")[0];
    // The array 0 assumes there is only one of these links,
    // you would have to loop or use event delegation for multiples
    // but we won't go into that here
    libLink.onmouseover = function () {
      this.style.color='#0F0'
    }
    libLink.onmouseout = function () {
      this.style.color='#00F'
    }

提交回复
热议问题