Currently, I am working on a feature that involves toggling the struck-through style of a span element when clicked. After experimenting with an if statement to determine the textDecoration attribute's value using console.dir(x)
, I found that the returned value is textDecoration:""
. How can I incorporate this into an if statement?
var x = document.querySelectorAll("span")
for(var i=0; i<x.length; i++){
x[i].addEventListener("click", function(){
if(this.style.textDecoration = ""){
this.style.textDecoration = "line-through"
}
else{
this.style.textDecoration = ""
}
})
}
Update: Despite the current code implementation, clicking the span element does not trigger any changes visually.