Q:

Getting information on a JS constructed button on click

Is it possible to get information, such as the id, value, of a button created by a javascript loop? For example, the following code, which creates a button for each line in a table formed by an array of objects?
    var table = document.createElement("TABLE");
    table.setAttribute("id", "tableOfArray");

    var array = [ (a large array of objects here) ];
    for (var i = 0; i < array.length; i++)
    {
        row = table.insertRow(i);
        cell1 = row.insertCell(0);
        cell2 = row.insertCell(1);
        cell3 = row.insertCell(2);
        cell4 = row.insertCell(3);
        cell5 = row.insertCell(4);
        cell6 = row.insertCell(5);

        cell1.innerHTML = i + 1;    //for numbering the table       
        cell2.innerHTML = array[i].property1;
        cell3.innerHTML = array[i].property2;
        cell4.innerHTML = array[i].property3;
        cell5.innerHTML = array[i].property4;

        var button = document.createElement("BUTTON");
        var buttonText = document.createTextNode("Remove Line");
        button.appendChild(buttonText);

        button.setAttribute("id", String(i));
        button.setAttribute("value", String(i));
        button.setAttribute("onClick", "remove()");

        cell6.appendChild(button);
    }

    function remove()
    {
        ?? //gets the value of the button that was pressed
        var buttonValue = ??; //assigns the value of button to the variable
        arrayTable = document.getElementById("tableOfArray");

        table.deleteRow(buttonValue);
    }

Is there a method that can be used to get the id or value of the button in order to perform the remove action?

A:

you can pass the current context by passing this
button.setAttribute("onClick", "remove(this.id)");
function remove(id){
 var _id=id;// id of the button;
}

Else you can use the event object
function remove(event){
 var _target = event.target;
  var _getId = _target.id;
 var _getParentTD = _target.parentElement; // will give the td which contain button
var _getParentTR = _target.parentElement.parentElement; // will return tr
}

