JQuery function on click does not work after adding list items

I have a simple click event using a function on:

$('#listnav li').on({
    click: function(event) {
        console.log('hello world')              
    }, 
    mouseover: function(event) {
        // do something
    }

});

This works for ul list with id "listnav". But when I add new entries to ul using the jQuery function append, this function is not called on the newly added list items. How can i fix this?

+4
source share
1 answer

I also faced the same problem

- ( ul), . DOM, append. click append .

, .

+5

Source: https://habr.com/ru/post/1691230/


All Articles