Chartjs-How can I set a class to a HTML element which is created by custom tooltip function?

2👍

Well, it seems like you can add a class name to the table inside #chartjs-tooltip directly by document.querySelector("#chartjs-tooltip > table").classList.add("[Your Class]")

or, since you have already had var tableRoot = tooltipEl.querySelector('table');, just add tableRoot.classList.add("[Your Class]") below.

0👍

may be a usefull, instead a add or remove a toggle principle:

var toggleRed = function() {
  document.querySelector('#sss').classList.toggle('red-box');
}
.box {
  display: block;
  width: 200px;
  height: 100px;
  border: 1px solid red;
}

.red-box {
  background-color: crimson;
}
<div id="sss" class="box"></div>

<button onclick="toggleRed()">toggle red</button>

Leave a comment