Is there a well-known mistake I could be making here?
I've got a script that's using .on() because an element is dynamically generated, and it isn't working. Just to test it out, I replaced the selector with the dynamic element's wrap, which is static, and it still didn't work! When I switched to plain old .click for the wrap it worked, though.
(This just won't work for the dynamic element obviously, the one that matters.)
This works:
$("#test-element").click(function() {
alert("click");
});
This doesn't:
$(document).on("click","#test-element",function() {
alert("click");
});
UPDATE:
I right-clicked and did "Inspect Element" in Chrome to just double-check something, and then after that the click event worked. I refreshed and it didn't work, inspected element, and then it worked. What does this mean?
:)
or flick a fiddle I might help you out, – Isopiesticon
function was added in jquery 1.7, make sure you have a recent version. Edit : proof for you that it works on fiddle – Bobo$('#test-element').on("click","*",function()
or$(document).on("click","#test-element *",function()
this will attach event handler to children. – Bonnett$(document).ready()
– Rotate