Will
Will

Reputation: 924

Document Ready equivalent for ajax-loaded content via jQuery Mobile accordion

As the super-long title suggests, I'm needing something of a jQuery Document Ready equivalent that will work with dynamically-loaded content that's loaded via ajax in a jQuery Mobile accordion/collapsible.

We have a few things that WON'T work as well:

  1. Can't add javascript to the actual markup itself (due to CMS) so it has to be loaded via the global js file.
  2. $(document).ready() won't work because it's not technically the document that we're waiting to load.
  3. $('div#id').load() doesn't seem to work.
  4. $('div#id').ready() seems to run anytime the actual page is loaded, regardless of whether the collapsible content is run.

This is kind of a shot in the dark, but anything you guys can help with, I'm grateful for :).

Thanks

Upvotes: 5

Views: 3949

Answers (1)

Muhammad Usman
Muhammad Usman

Reputation: 12503

Use .ajaxComplete()

$(document).ajaxComplete(function(e, xhr, settings){

});

If you want to do something when document has something new added then:

$(document).on('DOMNodeInserted', function(e) {

});

Upvotes: 20

Related Questions