2

I have a jQuery click binding within a knockoutJS foreach, and it's not working. I believe that knockout is stopping the propagation.

Is there a way to make it work? I'm trying to avoid binding to click event with knockout.

2
  • 2
    Can you post some code? Maybe in a JSFiddle? By the way you should return true in your KO event handler to propagate the event. Commented Dec 31, 2012 at 14:26
  • 2
    if you don't share your code it's going to be difficult to help you Commented Dec 31, 2012 at 14:26

1 Answer 1

12

Without seeing any of the code, I can only assume that you are doing something similar to

$('element').on('click', function(e){});

To bind a click event to dynamically generated objects you need to have your click events like this

$('body').on('click', 'element', function(e){});
Sign up to request clarification or add additional context in comments.

2 Comments

Dynamic, of course :) You are correct. I used $(elem).live("click" , function(e){}); Instead of $(elem).click(function(e){});
ah gawd that is annoying. Why don't they just stop propagation when you used the KO click binder? And jquery.live is now deprecated. Using the jquery.on() and attaching to root worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.