dimanche 10 décembre 2017

Add css to table when checking checkbox in Javascript

I try to make a function when a checkbox is checked, the table where the checkbox is in will turn in another color (the css-style ".table-bordered-selected")

Here is my HTML code:

<div>
  <table class="table table-bordered table-module" onclick="moduleClicked(this, event)">
    <tbody>
      <tr>
        <td>
          <label>
            <input type="checkbox" onchange="moduleSelect(this, 'contracts')">
          </label>
        </td>
      </tr>
    </tbody>
  </table>
</div>

And here is the Javascript:

function moduleSelect(checkbox, module) {
      if (checkbox.checked) {
        document.getElementById("module-" + module + "-summary-box").style.display = "flex"
        document.getElementsByClassName("table-module").classList.add("table-bordered-selected")
      }
      else {
        document.getElementById("module-" + module + "-summary-box").style.display = "none"
      }

What am i doing wrong?




Aucun commentaire:

Enregistrer un commentaire