How to loop through buttons in javascript?
<p>I have number of different buttons on my website and I want to assign different task to each button, currently I am referencing them one by one using <code>getElementByID</code> and because I have so many buttons I ended up writing endless lines of codes just to reference the buttons, having some knowledge of java I understand that what I have done could be achieved with less code using for loop but I am not quite sure how  to go about doing that, any help is welcomed.</p>

<p>Currently this is how I am referencing my buttons:</p>

<pre><code>    var Button1Menu = document.getElementById("button1menu"); 
    var Button2Menu = document.getElementById("button2menu"); 
    var Button3Menu = document.getElementById("button3menu"); 
    var Button4Menu = document.getElementById("button4menu"); 
    var Button5Menu = document.getElementById("button5menu"); 
    var Button6Menu = document.getElementById("button6menu"); 
    var Button7Menu = document.getElementById("button7menu"); 
    var Button8Menu = document.getElementById("button8menu"); 
    var Button9Menu = document.getElementById("button9menu"); 
    .....
    .....
    .....
    var Button43Menu = document.getElementById("button43menu"); 
</code></pre>

<p>and then I am assigning click listener to each one:</p>

<pre><code>Button1Menu.onclick = function() {

     //doing something

  };
</code></pre>

<p>Is there a better way of achieving this please.</p>