0

what im trying to write is a function that will be activated by a click that will run if the class name of the clicked element is correct. then change the class name to another state so it can not be run again until another part of the function reverts it. it will roughly look like this:

king1.addEventListener("click", turn);

function turn() {
 if (this.className="nf") {
  this.className="f"
   ...run more functions after
 };
 
}
liam smith
  • 21
  • 3
  • 3
    `=` equals assignment. `==` / `===` equals comparison. – Curtis Sep 01 '17 at 09:50
  • This is the second post I found with same problem. `=` means assignment. Use `==` or `===` to compare – Rajesh Sep 01 '17 at 09:50
  • This might help: https://stackoverflow.com/questions/5898656/test-if-an-element-contains-a-class. Not marking duplicate as the real issue is use of operator – Rajesh Sep 01 '17 at 09:53

1 Answers1

3

Use classList property of the element with includes#Array or it's own contains functions.

if([...classList].includes('nf')){

}

or

if(classList.contains('nf')){

}
Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112