Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 83.3k

document.getElementsByClassName doesn't work with button

Jan 1 2023 3:18 PM

Hi

I have two buttons in aspx file and i want to use document.getElementsByClassName in javascript to reach them all in one time.

The problem is that class doesn't exist for button (only CcsClass) nor something like document.getElementsByCssClassName.

How can i fix this?

Thanks and happy new year.

 <div>
            <asp:Button ID="Button1" CssClass="menu" runat="server" Text="Button1" />
            <br />
            <asp:Button ID="Button2" CssClass="menu" runat="server" Text="Button2" />
</div>

<script type="text/javascript">

         for (i = 0; i < 2; i++) {
             var a1[i] = document.getElementsByClassName("menu");
             a1[i].onmouseover = txtover
             a1[i].onmouseout = txtout
         }
         function txtover() { this.style.color = "#BCAEA5" }
         function txtout() { this.style.color = "black" }
     </script>

 


Answers (8)