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

368
Visualizações
What's the reason the button isn't even clicking?

The button isnt working along with the dropdown option. Any changes I need to make?

import React, { Component, Fragment } from 'react'

export class MegaMenu extends Component {

    constructor(){
        super();
        this.MegaMenu = this.MegaMenu.bind();
    }

    componentDidMount(){
        this.MegaMenu();
    }


    MegaMenu(){
        var acc = document.getElementsByClassName("accordion");
        var accNum = acc.length;
        var i;
        for(i=0;i<accNum;i++){
            acc[i].addEventListener("click",function(){
                this.classList.toggle("active");
                var panel = this.nextElementSibling;
                if(panel.style.maxHeight){
                    panel.style.maxHeight = null;
                }else{
                    panel.style.maxHeight = panel.scrollHeight+ "px"
                }
            })
        }

    }
  render() {
    return (
      <div className='accordionMenuDiv'>
          <div className='accordionMenuDivInside'>

              <button className='accordion'>
                  <img className='accordionMenuIcon' src="https://cdn-icons-png.flaticon.com/128/739/739249.png" />&nbsp; Mens Clothing
              </button>
              <div className='panel'>
                  <ul>
                      <li><a href="a" className='accordionItem'>Mans T-shirt1</a></li>
                      <li><a href="a" className='accordionItem'>Mans T-shirt2</a></li>
                  </ul>
              </div>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use onClick hanlder on react element itself this should work ,

this.handler = (e) => {
e.target.classList.toggle('active');
var panel = e.target.nextElementSibling;
if (panel.style.maxHeight) {
  e.target.nextElementSibling.style.maxHeight = null;
} else {
  e.target.nextElementSibling.style.maxHeight = e.target.nextElementSibling.scrollHeight + 'px';
}};
<button className='accordion' onClick= {this.handler}>

attach the onclick where ever you require for all the classname button if too many button then use event bubbling on a parent element of all the button

about 4 years ago · Juan Pablo Isaza Relatório
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