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

187
Visualizações
Is there way to integrate the jQuery function toggle class in react js

I have a jQuery function for toggling the class in custom.js.so I integrate all the CSS, and bootstrap custom.js in a public folder in HTML, but all the other files work fine but custom.js is not working so I install the jQuery library & import the jQuery & custom.js in index.js but still the same problem. Is any other way to achieve this because I have more functions in custom.js.

import $ from 'jquery;
$(document).ready(function () {
    $(".mobile-filter-btn").click(function () {
        $(".plp-filter").addClass("visible");
    });
    $(".mob-heading-close-btn").click(function () {
        $(".plp-filter").removeClass("visible");
    });
 }
 <script type="text/jsx" src="%PUBLIC_URL%/assets/js/jquery-3.2.1.slim.min.js"></script>
    <script type="text/jsx" src="%PUBLIC_URL%/assets/js/popper.min.js"></script>
    <script type="text/jsx" src="%PUBLIC_URL%/assets/js/bootstrap.min.js"></script> 
  <script type="text/jsx" src="%PUBLIC_URL%/assets/js/custom.js"></script> 

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Actually I assume that it works as expected, but the problem is, you are trying to put click handlers when components with those classes are not rendered yet.

You can put those jquery code into a function, import it to your react component and then use it in "componentDidMount" or useEffect with empty array of dependencies (works like componentDidMount in functional components) depending on which components you are using.

This way you will make sure that everything is rendered and you have where to put you click handlers.

To check this, try to console.log $(".mobile-filter-btn") in your code. I expect it to be undefined.

Also this is not good idea to bring jquery to react. It might work not very good with it and produce a lot of bugs or maintenance problems

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