My goal is to delete and/or move the parent element of the button on the page when it is clicked. The DOM doesn't seem to respond to my click event. I think it has something to do with scope and global variables but I'm still a newbie. Here's what my code looks like.
var startButton = document.querySelectorAll('button[data-action="start"]');
var deleteButton = document.querySelectorAll('button[data-action="delete"]');
var element = document.getElementsByTagName('section');
var firstChildElement = element.firstChild;
startButton.addEventListener("click", toStart);
deleteButton.addEventListener("click", deleter);
/*function declarations*/
function toStart() {
element.insertBefore(this.parentNode, firstChildElement);
}
function deleter() {
element.removeChild(this.parentNode);
}
<section>
<article>
<h2>Item One </h2>
<p>Lorem ipsum dolor sit amet</p>
<button data-action="start">Move to start</button>
<button data-action="delete">Delete</button>
</article>
<article>
<h2>Item Two </h2>
<p>Lorem ipsum dolor sit amet</p>
<button data-action="start">Move to start</button>
<button data-action="delete">Delete</button>
</article>
<article>
<h2>Item Three </h2>
<p>Lorem ipsum dolor sit amet</p>
<button data-action="start">Move to start</button>
<button data-action="delete">Delete</button>
</article>
</section>