Answers for "how to give id dynamically in javascript"

0

how to give id dynamically in javascript

//Here the delete button gets a unique ID everytime, the ID is the array index of the element. 
array.forEach(function (element, index) {
      display =
        display +
        `<tr>
            <th scope="row">${index + 1}</th>
            <td>${element.first}</td>
            <td>${element.second}</td>
            <td>${element.third}</td>
            <td><button type="button" id="${index}" onclick="deleteNode(this.id)" class="btn btn-danger">Delete</button></td>
        </tr>`;
    });
Posted by: Guest on May-02-2021

Code answers related to "how to give id dynamically in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language