addEventListener
directly on the copied node (e.g. item). cloneNode does not copy
event handlers, so you cannot pre-hook them onto the template. Since the code in that loop over the retreived data
is getting more complex, you should refactor that code into a separate (named) function to keep it neat.
Note that mouseover and mouseout fire repeatedly as your mouse moves into and out of descendant elements.
mouseenter and mouseleave do not fire when your mouse moves into and out of descendant elements, making them
more appropriate in most situations.
this as it doesn't not rebind to the element with an "arrow" function.
// in this example, we use 'e', the handler event parameter, to access the target of the event
some_node.addEventListener('click', e => {
console.log("You clicked on " + e.currentTarget);
});
// in this example, we use the reference to the element that we already have (it's still in scope)
some_node.addEventListener('click', e => {
console.log("You clicked on " + some_node);
});
Once you have a reference to the root element, you use the same strategy that you used to manipulated the text, speaker, and source. Add
a unique-to-the-template class to the template row that you want to make visible, and then use getElementsByClassName in the
handler to get to it.
mouseenter event handler to the whole <li> so that the delete row appears on mouse over
mouseleave event handler to rehide the delete row