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

148
Views
In react how to detect the button id clicked on not

In this case when I clicked the button I want to access the button Id and also want to checked that button is clicked or not. here I have use the e.currentTarget.idto detect the button ID and want to checked that its clicked or not by using document.getElementById("yourID").clicked === true. But after clicking the button its not give the alert. So how do I achieved that

import * as React from "react";
export default function Map() {
  const getButtonId = (e) => {
    if (e.currentTarget.id === "yourID") {
      if (document.getElementById("yourID").clicked === true) {
        alert("button clicked");
      }
    }
  };
  return (
    <div>
      <button id="yourID" onClick={getButtonId}>
        Button
      </button>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First of all there is no need to use document.getElementById("yourID").clicked === true because button has onClick property that you are using which does what you want.

And as to solve your problem, you have a typo in your code. You typed yourId in e.currentTarget.id === "yourID" instead of yourID

const getButtonId = (e) => {
    if (e.currentTarget.id === "yourID") {
        alert("button clicked");
   }
}
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!