I have a ul and i want create an alert when i click on a child li.
-
You can use
$(document).on('click','#myul li', eventHandler)
which means you're registering an event handler on the document but eventHandler
will be invoked only when the event originated from #myul li
i.e for any li
child of myul
, not just the immediate child, can be a descendant as well which fits your case.
But I suggest that you even reduce the scope of the event registration to the closest ancestor of li
like below.
$('#myul').on('click','li', eventHandler)