In an array of buttons, how can you tell which button was clicked?

Posted by Michael Seltenreich on Stack Overflow See other posts from Stack Overflow or by Michael Seltenreich
Published on 2013-10-24T21:47:31Z Indexed on 2013/10/24 21:54 UTC
Read the original article Hit count: 180

Filed under:

If I have an array of buttons, how can I tell which button was clicked? example below

 var i=0
 CreateButton = new function () {
    savebutton[i]=NewButton()
  i++
  }

every time a user runs the function a new button is generated. the first button is savebutton[0] the second is savebutton[1] and so on potentially infinity times.

when later the user presses the button I want the screen to alert it's index number (or 'i').

is there any way to make this work in arrays?

© Stack Overflow or respective owner

Related posts about JavaScript