开发者

Simple questions about ajax - Help me understand

开发者 https://www.devze.com 2022-12-19 13:15 出处:网络
I need a little help understanding something. I am using the colorbox plugin to load an external an external html snippet (which works fine). But none of my jquery selectors see the newly loaded html.

I need a little help understanding something. I am using the colorbox plugin to load an external an external html snippet (which works fine). But none of my jquery selectors see the newly loaded html. Is that right开发者_开发百科 (I think it is)? and if so how do I work around that.

Thanks


When you set any properties/bind events in your $(document).ready(function() { ... }) they are executed on page load. So it is all applied to the DOM elements that are present initially.

But when you call the AJAX request and insert some elements into your document, the jquery statements are not executed again (because document.ready doesn't fire). Some solutions to overcome this are:

  • execute the inside of the document.ready function or the relevant part of it after you insert the new elements.
  • if the only thing you need are event handlers that should be bound the the new elements you may use live events.
0

精彩评论

暂无评论...
验证码 换一张
取 消