Message from JavaScript discussions

October 2017

— Give an id to the button and use document.getElementById


my_table.on('click', 'button.editor_remove', function (e) {
document.getElementById('delete_pk').value = e.element.getAttribute('data-pk');

— I wanna set document.getElementById('delete_pk').value to data-pk value

— With this code its said e.element is undefined

— How to get the element triggered?

— Well, get a reference to that element?

— Document.getElementById(#yourId).getAttribute('data-pk')

— The e?

— I have so many button so i cant do this 😕

— document.querySelector('button.btn.btn-danger.btn-xs.editor_remove');

— If you don't want that long string, just create an ID per button

— Or traverse the DOM tree based on the location of the other button you click on