This is a really easy one, but I can’t get it to work. I have the following (old) function that deals with clicks on my carousel:
$('#cycleDiv img').live('click', function () {
alert('hh');
});
Since .live is a badbad thing, I’d like to convert this simple function to .on, but by replacing live, nothing happens. I’ve also tried:
$('#cycleDiv').on('click', 'img', function () {
alert('hh');
});
But nothing happens. I’ve looked at the documentation, but I can’t figure this out.
Also, the images are loaded with ajax, so this is dealing with dynamic content. I know .on works on the static elements on my site.
What am I doing wrong?
If the DIV is being added via AJAX as well, you’ll need to delegate the handler to the document. See if this works: