javascript - how to judge which button has been clicked using there className instead of ID -
I have 100 buttons in a table, but the name of the same class is different but different IDs C-1, C -2, ...., cn & lt; Input type = "button" class = "btn-c" id = "c-1" value = "ADD" & gt;
How do I know which button is clicked using their classname and whithout & lt; Input type = "button" ... onclick = "call_function (this);" For simplicity,
says that I want warning (button id);
Click on any of the 100 buttons
If you have a lot of buttons, it It is understood to use the event delegation:
$ ('table'). ('Click', '.btn-c', function () {warning (this.id); // will click on the button ID}};
Performance approaches This is an optimum approach because you only force an event handler in parent element and get benefit from child element eventbulbling.
UPD. This is a The pure JavaScript version of the code is:
document.getElementById ('Table'). AddEventListener ('click', function (e) {if (/ \ bbtn-c \ b / .test (E. Target.className)) {warning (e.target.id);}}, false);
Comments
Post a Comment