PW Kad
PW Kad

Reputation: 14995

Strip element of Knockout binding

Quick question that I am probably just having a hard time asking correctly and therefore having a hard time figuring out how to accomplish this -

http://jsfiddle.net/RsKUS/

When I click on the div I want to take one action but if there is a button nested inside the div I only want to perform that action, not both.

<div data-bind="click: clickOne">
    <p>It's here too...</p>
    <button data-bind="click: clickTwo">Child</button>
</div>

Upvotes: 0

Views: 70

Answers (1)

nemesv
nemesv

Reputation: 139788

You need to set the clickBubble: false on the inner handler to prevent the click event bubbling:

<div data-bind="click: clickOne">
    <p>It's here too...</p>
    <button data-bind="click: clickTwo, clickBubble: false">Child</button>
</div>

Demo JSFiddle.

See also in the click binding documentation: Note 4: Preventing the event from bubbling

Upvotes: 2

Related Questions