Skip to content Skip to sidebar Skip to footer

Jquery Click() Event Won't Work For Appended Html Tags

There are a couple of things I need to explain before my question makes sense. On my first page I have a main div where I'm loading markup from another page using the jquery load()

Solution 1:

I found an answer here: Newly appended div doesn't inherit event handler in document ready

The shortcut event handlers (such as click(), mouseover() etc) will only apply to elements which are available to the DOM on page load. When appending elements dynamically you have to attach the event to a static parent element, and supply a filter which you wish to delegate events to, like this:

This was my solution:

$("#mainDiv").on('click', '.interested', function(){
       alert("working");
   });

Post a Comment for "Jquery Click() Event Won't Work For Appended Html Tags"