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

302
Views
Onclick on button is not working in ReactJs

I am working with Reactjs (Nextjs),I put my "css,images,js" files in "public" folder,But my Menu bar is not showing (onclick is not working),How can i make this working so after click on this button menu will display,Here is my code

<button className="openbtn" onclick="openNav()">
        <img src="images/menu_btn.png" />
</button>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Firstly you're passing openNav as a string, rather than a function - you can't invoke a string literal.

Secondly, you're trying to instantly invoke the openNav function in the onclick handler, which means openNav will fire as the code is run in the browser.

You'll want to do either:

onClick={openNav}

or if you want to pass an argument

onClick={(arg) => openNav(arg)}
about 4 years ago · Juan Pablo Isaza Report

0

You are sending a string to onClick function, so change your onClick button to this,

onClick={ openNav }
about 4 years ago · Juan Pablo Isaza Report

0

As others are mentioning, you need your onClick attribute to call a handler function, ie.

const openNav = () => {
   console.log("openNav has been clicked");
}

<button className="openbtn" onClick={openNav}>
        <img src="images/menu_btn.png" />
</button>

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!