Simple questions about ajax - Help me understand
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.
精彩评论