1
I’m creating a tooltips sketch, so that when you click on a certain span, this span shows a message
HTML
<div class="banner-tooltips" id="banner-tooltips">
<span id="primeira-tooltip">1°</span>
<span id="segunda-tooltip">2°</span>
<span id="terceira-tooltip">3°</span>
<span id="quarta-tooltip">4°</span>
</div>
JS
function tooltips(){
var caixaTooltips=document.getElementById("banner-tooltips");
var tooltips=caixaTooltips.querySelectorAll("span");
for(var i=0;i<tooltips.length;i++){
tooltips[i].addEventListener("click",function(){
var anterior=document.getElementsByClassName("banner-tooltip-active");
console.log(anterior);
if(anterior.length!=0){
console.log(anterior);
anterior.classList.remove("banner-tooltip-active");
}
console.log(anterior);
this.classList.add("banner-tooltip-active");
});
}
}
tooltips();
When you click on the first tooltip, it opens a good one, but when you click a second time, it says that you cannot remove the Undefined class. Why this happens, and how can I solve the problem?
you know tell me, how can I do so that by clicking outside the main box, it removes all "banner-tooltip-active" classes from the child spans ?
– Murilo Melo
Yes @Murilogambôa, it is a good question, it is better in another topic =]
– BrTkCa
I have created aheuhae :D
– Murilo Melo