Valerie Meunier

Valerie Meunier

  • 962
  • 693
  • 71.9k

how to simplify this?

Sep 2 2022 9:50 PM


I want to apply onmouseover / out to each of the elements of <li>. I only can use one time the id="a1", so this code works only for the first element. Putting the id in the <di> like <div id="a1"> doesn't work. Thanks for help. V

            <li> <a id="a1" hef="#">Welcome</a> </li>
            <li> <a hef="#">Contact</a> </li>
            <li> <a hef="#">Info</a> </li>

    <script type="text/javascript">
        var a = document.getElementById("a1");
        a.onmouseover = txtover
        a.onmouseout = txtout

        function txtover() { = "red"; }
        function txtout() { = "green"; }

Answers (2)