else if (thumbnailElement.className = “”)
Note the single=”s, this should be ===
You are also performing the same comparison twice in the first if and if else.
if (thumbnailElement.className == "") {
thumbnailElement.className = "small"
} else if (thumbnailElement.className = "") { <-- this is the same as the first one, but it"s the wrong syntax
thumbnailElement.className = "small"
}
There are also other small issues in your syntax which aren’t going to work.
var thumbnailElement = document.getElementById ("smart_thumbnail");
thumbnailElement.className; <--- this isnt doing anything
thumbnailElement.className = ""; <--- every time you run the function you automatically remove the class
Try this:
thumbnailElement.addEventListener("click", function () {
if(thumbnailElement.classList.contains("big"){
thumbnailElement.classList.remove("big")
thumbnailElement.classList.add("small")
}
}
https://jsfiddle.net/2xb4azyn/ I’ve created a fiddle with a working example
0
solved conditionall if == on javascript