-1

I'm trying to toggle the visibility of columns with a click of a button, however the button doesn't seem to be working. Could anyone please help me with this?

The column I'm trying to toggle: {{Kanji}}

function toggleKH() {
  var i;
  var kcol = document.getElementsByClassName("kanjiColumn");
  var hcol = document.getElementsByClassName("hiraganaColumn");
  for (i = 0; i < kcol.length; i++) {
    if (kcol[i].style.visibility === "visible") {
      kcol[i].style.visibility === "hidden";
    } else {
      kcol[i].style.visibility === "visible";
    }
  }
}
.kanjiColumn,
.hiraganaColumn {
  visibility: visible;
}
<button onclick="toggleKH()">x</button>


<td class="kanjiColumn">{{Kanji}}</td>
Jos van Weesel
  • 2,128
  • 2
  • 12
  • 27
Chunky Low
  • 69
  • 7

1 Answers1

2

replace ===(equality conditional operator) with =(assignment operator) inside if-else statement as below:

   if (kcol[i].style.visibility === "visible"){
            kcol[i].style.visibility = "hidden";
        } else {
            kcol[i].style.visibility ="visible";
        }
Rashedul.Rubel
  • 3,446
  • 25
  • 36