Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda