Используйте метод .on()
с подписью $(common_parent).on(event_name, filter_selector, event_listener)
.
$(function() {
$("ul").on("click", "li", function() {
// here I want to get the clicked id of the li (e.g. bakkerLink)
var id = this.id;
alert(id);
});
});
Другой метод - привязать событие к li
вместо ul
:
$(function() {
$("li").click(function() {
// here I want to get the clicked id of the li (e.g. bakkerLink)
var id = this.id;
alert(id);
});
});