Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery doesn’t execute on div loaded with ajax Re: jQuery doesn’t execute on div loaded with ajax

#121407
Mottie
Member

I’m not sure what I can help with without seeing any of your code. So here’s an example.

If you have a div that has content loaded dynamically (using ajax), you can open an alert popup to elements with a class name of “alert” to that dynamic content using `delegate` (or `on` if you are using jQuery 1.7+) like this:

HTML

Javascript

$(function(){
// .on(‘click’, ‘.alert’, function(){
$(‘#dynamic-content’).delegate(‘.alert’, ‘click’, function(){
alert( $(this).html() );
});
});