In my code I am attempting to update the innerHTML of a button on a mouseenter event.
I would expect the event to fire once each time my mouse moves into the element, but instead while my mouse is moving within the element, the event listener fires multiple times. If I remove the line updating the innerHTML within my event listener I get the expected behavior.
Why is this and how can I fix it? Please see the below code and linked JSFiddle.
https://jsfiddle.net/h7gsv69m/2/
var box = document.getElementById('box');
var button = document.createElement('button');
button.innerHTML = '<svg><use xlink:href="#icon-added"></use></svg>';
button.addEventListener('mouseenter', function() {
document.getElementById('log').innerHTML += '<li>Mouseenter</li>';
var iconHover = this.dataset.iconHover;
//Comment out the following line to see expected behavior.
this.innerHTML = '<svg><use xlink:href="#icon-remove"></use></svg>';
});
box.appendChild(button);