Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!