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

138
Vistas
The following IIFE is working fine from local directory but not working after integrating to React app

Following code is working fine when browsed from local directory but not working after integrating into a ReactJS app.

I have downloaded an online template to integrate to React application. It has main.js file. It includes css class based events that's not working after integrating to the React App

(function () {
    "use strict";

    function select(el, all = false) {
        el = el.trim()
        if (all) {
            return [...document.querySelectorAll(el)]
        } else {
            return document.querySelector(el)
        }
    }

    function on(type, el, listener, all = false) {
            if (all) {
            select(el, all).forEach(e => e.addEventListener(type,
                listener))
        } else {
            select(el, all).addEventListener(type, listener)
        }
    }

    function onscroll(el, listener) {
        el.addEventListener('scroll', listener)
    }

    /**
      * control is not going inside if condition because 
      * `select('.toggle-sidebar-btn')` is not getting called. 
      * Even on (type, el, listener, all = false) method is also
      * not invoked after integrating to React App
      */

    if (select('.toggle-sidebar-btn')) {
        on('click', '.toggle-sidebar-btn', function (e) {
            select('body').classList.toggle('toggle-sidebar')
        })
    }
})();
about 4 years ago · Juan Pablo Isaza
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