Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda