0

I am using knockout ver. 2.3.0. Click binding is handled by more than one element in ie8. Example:

<div>
  <div>
        <span data-bind="click: changeSomething">click me</span>
  </div>  
  <someother tags>...</someother tags>
</div>

Here action changeSomething is called not only by clicking span element. If I click 'someother tags' changeSomething is triggered. I think only items below the span are exposed and it's more random than the first case. Not sure if this is related, but I also use jquery ver 1.10.2, jqueryui ver 1.10.2.

Sorry for lack of fiddle, but I cannot reproduce it in a simple environment.

Mat38
  • 97
  • 1
  • 12

1 Answers1

1

The problem you are most likely seeing is called bubbling. You need to prevent bubbling. This isn't just an IE8 problem, it is all browsers.

The only other way it would give the click event handler is if your jQuery or view model told it to handle anything clicked, as KO is fully functional in IE8.

<div data-bind="click: myDivHandler">
    <button data-bind="click: myButtonHandler, clickBubble: false">
        Click me
    </button>
</div>

You can read the docs here

http://knockoutjs.com/documentation/click-binding.html

example -

http://jsfiddle.net/XPtAY/

PW Kad
  • 14,953
  • 7
  • 49
  • 82
  • Thanks for reply. I thought about it, but it's not it. I don't have nested tags with click binding. I have siblings(or parent) that are also handling that click. And it only happens in IE8, in IE9/Firefox/Chrome everything is fine. Tags are fine, if jQuery is handling parent event, then it's unintentional‎. Can I somehow inspect that? When, how, a binding is added for specified element? – Mat38 Aug 02 '13 at 07:18
  • I found similar problem [here](http://stackoverflow.com/questions/16453003/knockout-js-and-with-binding-in-ie8-corrupts-page). Using instead of solved problem(although using prefixes everywhere complicates code and makes it longer) – Mat38 Aug 02 '13 at 07:47
  • Are you sure you are closing all the tags by the proper conventions? – PW Kad Aug 02 '13 at 11:03
  • Yes, I am, checked it a few times. – Mat38 Aug 02 '13 at 14:00
  • Can you paste a sample of the code that is causing the issue? Maybe if we can't repro it we can at least see what might be a contributing factor – PW Kad Aug 02 '13 at 16:42