Message from JavaScript discussions

October 2017

— Halp


How to get data-pk value using js from this element?

<button type="button" class="btn btn-danger btn-xs editor_remove" data-pk="1">Delete</button>

— button.getAttribute('data-pk')

— Button is not defined

— 😕

— Oh wait

— 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');

Message permanent page

— 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?