0

In HTML I'm trying to change the hover and visited color property/attribute of an anchor tag using JavaScript.

Here is my code that doesn't work:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <script>
      function changeAttributes() {
        document.getElementById("idA"):hover.style.color = "ccffcc";
        document.getElementById("idA"):visited.style.color = "ffcccc";
      }
    </script>
  </head>
  <body onload="changeAttributes();">
    <a id="idA" href="#">Target text</a>
  </body>
</html>
Graeme Jensz
  • 267
  • 4
  • 16
  • Hello, I think you need to understand more about js programming language, its syntax, Etc. – Ele Jun 11 '18 at 00:22

1 Answers1

0

Just use CSS for this

#ida:hover {
   color: #ccffcc;
}

If you really want to use javascript I think you should use the onMouseOver and onMouseOut events

<a 
  id="idA" 
  href="#" 
  onMouseOver="this.style.color='#ccffcc'"  
  onMouseOut="this.style.color='initial'">
      Target text
</a>

Still would highly recommend handling these pseudo events with CSS

Jason McFarlane
  • 2,048
  • 3
  • 18
  • 30