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

心不动则不痛 提交于 2020-01-13 01:48:45

问题


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


回答1:


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) {

});


来源:https://stackoverflow.com/questions/8912411/document-ready-equivalent-for-ajax-loaded-content-via-jquery-mobile-accordion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!