I am wondering if there is a way to select a specific element way up the DOM only using vanilla JS while not having to use parentNode
multiple times. I understand you can do this with jQuery and modifying Element.prototype
, but are there any other pretty ways to write this.
const deleteButtons = document.querySelectorAll('.delete-button');
for (var i = 0; i < deleteButtons.length; i++) {
deleteButtons[i].addEventListener('click', (e) => {
e.preventDefault();
//This is the crazy amount of parentNode usage
bookDatabase.child(e.target.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute("id")).remove();
});
}