I could not reproduce this in the chrome version that I am using.
But if you come across this in some browser, probably because -
According to the specification, labels containing inputs and those that are connected to the input through the for attribute cause a click on the corresponding input when pressed.
So, in your first case there are 2 click events:
- Actual click on
<label> - Press the
<input> button by pressing the button
What fires on <input> will bubble up to <label> and fire your handler.
In the second case, since the for attribute is specified and there is no corresponding input with id in 'test', an additional click does not start even if the input is inside the label.
source share