I'm binding a click event to buttons created dynamically in a table of class .lada-button
.
In the current setup creating a reference to the button using a class selector Ladda.create( document.querySelector( '.ladda-button' ) );
triggers the submit transition only for the first button in the table. Instead of the button that has been clicked.
So in order to trigger it for the button that had been clicked, I tried getting the id of the clicked button which returns undefined for the id
attribute:
<tbody>
@foreach (var row in Model.Status)
{
<tr>
<td style="visibility:hidden;" >@Html.Raw(row.ID)</td>
<td><button type="submit" data-style="expand-right" class="ladda-button"><span class="ladda-label">Update</span><span class="ladda-spinner"></span></button></td>
</tr>
}
</tbody>
$(".ladda-button").click(function () {
var btnId = $(this).attr('id');
alert(btnId);
var updateBtn = Ladda.create( document.querySelector( btnId ) );
// Start loading
updateBtn.start();
});
How can you get the id attribute of clicked tr button element?