javascript - Clicking on an input[checkbox]'s label will fire twice the parent's click event (knockout) -
consider this fiddle. have <input type='checkbox'> linked corresponding <label>. on parent, have click binding.
the problem is, clicking on <label> trigger parent's click twice, whereas clicking on <input> trigger once.
considering want keep current html structure (<label> next <input>), there way make <label> behave <input> element? (aka trigger click once)
edit: if remove return true; statement click handler's function, wont trigger twice, also, won't select checkbox. selecting checkbox required. here case don't have action on parent element. if click on <label>, check <input>.
i found answer here. trick make label stop bubbling custom binding.
<label for="test" data-bind="stopbubble:parentaction">testlabel</label> the stopbubble binding @ link, , in fiddle.
Comments
Post a Comment