Dean_Geva
Dean_Geva

Reputation: 49

onClick function doesnt take the value when i click on elements inside the button

function handleClick(e) {
     console.log(e.target.value)
}

<Button value={id} onClick={handleClick} id="like-button" variant="light">
  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" 
      fill="currentColor" className="bi bi-heart-fill" viewBox="0 0 16 16">
   <path fillRule="evenodd" d="M8 1.314C12.438-3.248 23.534 4.735 8 15-7.534 4.736 3.562-3.248 8 1.314z" />
  </svg>
  <p>Like</p>
</Button>

when i click on the button i get the value id, but if i click on elements inside the button i get the value of the element that got clicked. any idea how can i get the value -id- no matter where i clicked on?

Upvotes: 1

Views: 505

Answers (1)

wangdev87
wangdev87

Reputation: 8751

use event.currentTarget instead of event.target

Upvotes: 4

Related Questions