As said above, I want to have JS cycle through textDecoration as I click on a span. I found a fragment of this in another answer that I cannot find anymore and (tried to) modify it.
HTML
<div id="container">
<span>A</span> <span>B</span> <span>C</span> <span>D</span>
</div>
JS
var container = document.getElementById("container");
if (container.addEventListener) {
container.addEventListener('click', clickHandler, false);
}
else if (container.attachEvent) {
container.attachEvent('onclick', function(e) {
return clickHandler.call(container, e || window.event);
});
}
function clickHandler(event) {
var span = event.target;
if (span.style.textDecoration == 'none') {
span.style.textDecoration = 'underline'
}
else if (span.style.textDecoration == 'underline') {
span.style.textDecoration = 'line-through'
}
else if (span.style.textDecoration == 'line-through') {
span.style.textDecoration = 'none'
}
}
I think the issue is with using span as the object, but I am not sure how to do it more correctly.