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

108
Views
Removing disabled HTML attribute from a button does not allow to click it

I have this button component in my React application:

<button onClick={() =>alert('hi')} disabled={true}>test</button>

I expected when I will remove disabled attribute in browser like:

<button disabled>test</button>

to:

<button>test</button>

The button should be clicked and alert should appear but it did not happen.

Why is the button not triggering alert message after removing the attribute inside the browser?

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

0

The <button> you render with react is not the actual DOM element but a built-in component, that manages its state internally. So the props you pass to that component only get reflected in the DOM when react re-renders it when props or state have changed.

But React doesn't know you removed the disabled attribute in the DOM. From the perspective of react, the button is still disabled and click events are therefore suppressed. When managing the DOM with react you should not try to manipulate the DOM from outside as react will not be aware of any changes and they will be overridden with every render.

Also events on built-in components are managed by reacts own event handling. So the handler you passed to the <button> component is not the same as if you provided it directly to the DOM element.

about 4 years ago · Juan Pablo Isaza Report

0

As per your code, I can see that you did not remove the disabled attribute. You only removed the {true} part. Keeping the disabled attribute, even if it is not set to true, will still disable the button, which is why it is not getting triggered. Try this :-

<button onClick={() => alert("hi")}>test</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!