4

I have a simple click event using the on function:

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

});

This is working for the ul list with id "listnav". But when I am adding new entries to the ul using jQuery's append function, this function is not called on the new added list items. How can I fix this?

Caspert
  • 4,197
  • 14
  • 52
  • 97

1 Answers1

5

I have also faced same issue,

While you dynamically append anything (here you are adding new entries to ul), you need to bind its event too. as event is already binded when DOM is loaded and the append is made later on. You need to define the click function within the function of Append after your required append is done.

Hope this helps.

sSD
  • 264
  • 2
  • 16
Divya
  • 1,163
  • 2
  • 11
  • 31