0

When I click tag <button>, tag <a> clicked directly. How to solve it? or any other way? enter image description here

Hash
  • 7,726
  • 9
  • 34
  • 53
Derry
  • 79
  • 1
  • 11

2 Answers2

4

tag <button> is child of tag <a>, that's why tag <a> clicked when you click <button>. Create tag <button> as sibling of tag <a> and position it over image with the help of css.

<a href="#">
   <image src="">
</a>
<button>View<button>

Also use higher z-index for <button> to make it over tag <a>.

K Ravi
  • 729
  • 8
  • 25
3

I think that's not possible. But, you can try removing the <a> tag or add pointer-events: none to the <a> tag.

The reason is, you're enclosed the button with a link tag. This make the button a link. So, clicking the button will trigger a click event on the enclosing link.

This can be handled via event.target and event.currentTarget in JavaScript.

Hope this helps!

Pranesh Ravi
  • 18,642
  • 9
  • 46
  • 70