jQuery dynamic content loaded via Ajax

Hey all i am trying to close a div that displays when the page loads. However, doing this:

jQuery(document).ready(function () {
   jQuery('#moreDetailsTable').slideUp("fast", function () {});
});

Doesnt seem to close it when the page loads since its dynamicly being populated via PHP code using ajax.

The php that ajax calls looks like this:

echo '<div id="moreDetailsTable" class="widefat fixed comments">
    Testing this out<br />
    Testing this out<br />
    Testing this out<br />
    Testing this out<br />
    Testing this out<br />
</div>
   ect ect.....

I know the code work because i just do this:

jQuery(document).on('click', '#moreDetailsTable', function() {
    jQuery('#moreDetailsTable').slideUp("fast", function () {
        console.log('done');
    });
});

And it slides up once i click on it.

How can i called the .slideUp since its dynamically populated and not on the page to start with?

Answers


Please see the jQuery.ajaxComplete() event handler. This will do what you want.

Example:

jQuery(document).ajaxComplete(function () {
   jQuery('#moreDetailsTable').slideUp("fast", function () {});
});

Need Your Help

How to get JSON data through ajax in jPut

javascript jquery html ajax

I found a useful jQuery plugin for appending JSON data to HTML contents in an easy way in this link Jput plugin

Best practices for blitting in flash as3

flash actionscript-3 flash-cs4

I am creating a blit game and as of right now, the only thing that is blitting is the world itself (i.e. roads, fences). i was planning on displaying my character as a sprite and any interactive ob...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.