2

I'm getting mad about this.Long story short :
This is the show-cart.php where cart is shown.

enter image description here

When i click Remove button , the event I call works 1 over 10 times about.Below it's the simple code.What's wrong? Why it's not working properly?

<button type="button" class="btn btn-danger">
                            <span onclick="alert('smth')"; class="glyphicon glyphicon-remove""></span> Remove
                        </button>

This is my console enter image description here

Cristiano Soleti
  • 805
  • 7
  • 12

1 Answers1

2

Try putting the onclick function on the button element instead of span. The following snippet shows this along with some other cleanup in your code.

<button type="button" class="btn btn-danger" onclick="alert('smth')">
  <span class="glyphicon glyphicon-remove"></span> Remove
</button>
mrogers
  • 1,187
  • 2
  • 15
  • 22
  • Ok this is working. But why ? Is giving on click on span wrong? – Cristiano Soleti Jan 20 '17 at 22:55
  • There are a couple existing questions and answers which may help give some insight. I think the short version is that you might be able to make it work but it is not intuitive and is discouraged in practice for that reason. http://stackoverflow.com/questions/14689879/span-inside-button-is-not-clickable-in-ff – mrogers Jan 20 '17 at 23:02