I need some advice of understanding jQuery's .on() method. One of the cases when I'm using .on()
would be following:
I want to attach a clickhandler to an element which isn't already in the markup.
$('#somediv').on('click', '#trigger', function() {
// an awesome click event
});
$('#somediv').append('<span id="trigger">Click</span>');
My question now is, what if #somediv
wouldn't be in the markup as well. Which parent selector would I apply the .on()
method to. Can I just use $('body').on()
or is there a specific rule where to attach it.
Thanks