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

140
Views
Why can't a getElementById method find an element when imported inside functional component?

I want to use this cool scroll effect in one of my pages.The functional component has the same exact HTML as in the codepen. The script is in a separate file that is imported inside the component file. The problem is this line doesn't work

var well = document.getElementById('well');

I tried to import the JS-file into a variable and the call it in a useEffect hook just to make sure that hte script is run after the DOM is rendered. But it still doesn't work. What do I do to make the script work in my component?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Did you try importing the script like this ?

useEffect(() => {
    const script = document.createElement('script');
    script.src = "source of the js file";
    script.async = false;
    document.body.appendChild(script);
    return () => {
        document.body.removeChild(script);
      }
  }, []);
about 4 years ago · Juan Pablo Isaza Report
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!