Spending hours on trying to figure out why it does not check

31 Jul 2012

Yesterday I spent hours trying to figure out why a checkbox did not get checked (visually). When debugging the knockout code, it was clear that the DOM elements got checked. They did not update visually until another checkbox got checked. I tried other methods of checking the checkbox (both setAttribute and jquery) to no affect. What was even weirder is that it works the same in both chrome and IE.

To reproduce, click on the first checkbox and then the second in this fiddle.

I got the question if I had a click event handler from steal my code.

Turns out that the reason for this behavior is that I had a click event handler on a parent DOM element. By having the click handler return true the problem was resolved.

I still don’t understand why it works like this.



Do you want to send a comment or give me a hint about any issues with a blog post: Open up an issue on GitHub.

Do you want to fix an error or add a comment published on the blog? You can do a fork of this post and do a pull request on github.