Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

300
Visualizações
Cannot read properties of undefined (reading 'className')

Here is the js function that includes the className property:

function filterSelection(f){
var c, i;
c = document.getElementsByClassName("filterDiv");
if(f=="all") f="";
for(i = 0; i<c.length ;i++){
    classRemove(c[i], "show");
    if(c[i].className.indexOf(f) > -1) classAdd(c[i],"show");
}

}

I copied it straight from w3schools, with a few changes to variable names but that's it. Does the placement of my script tag have anything to do with this?

Here's the HTML code it applies to:

<div id = "btnContainer">
    <button class = "btn active" onclick = "filterSelection('all')"> All classes</button>
    <button class = "btn" onclick ="filterSelection('myclasses')"> My classes</button>
</div>
<div class = "container">
    <div class = "filterDiv <?php echo $bookmark1;?>">
    Test Class 1
    <button id = "addBtn-1" onclick = "noneAdd();add()">Add to My Classes</button>
    <button id = "removeBtn-1" class = "none" onclick = "noneRemove();remove()">Remove from My Classes</button>
    </div>
</div>

Ignore all the other elements, they most likely don't work but I'm confused as to why I'm getting this error specifically since it was a copy of w3schools' code.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda