jQuery is ready from dynamically loaded control
I have created an asp.net applicaton that contains a aspx that has an update panel. I have a button inside the update panel that loads usercontrols.
My usercontrol I am trying to use the jquery facebox plugin.
jQuery(document).ready(function ($) {
$('a[rel*=facebox]').facebox({
loadingImage: '/styles/images/facebox/loading.gif',
closeImage: '/styles/images/facebox/closelabel.png'
});
});
so for any anchor tag I want this plugin to work on I just need to add rel="facebox"
and it works nicely.
I have tried adding re开发者_JAVA百科l="facebox" to a tag I am wanting to use in my usercontrol however nothing happens apart from the anchor tag redircting me to the link reference in the href
I have tried adding the above documet.ready code to both the aspx & ascx however nothing happens.
Is this due to the dynamic loading of the usercontrol? is this some other steps I need to do to?
Any help would be great. Thank you
Yes, it would be because of the update panel. Code added dynamically to a page is not automatically matched by a jQuery selector, so event handlers will not fire. To get around this, you could either reregister the event handlers after loading the new code, or you can use live(). Since these handlers are registered within facebox, you may need to modify facebox's code. Here is one instance that would need changed: line 159
Time to start troubleshooting. Add this line: console.log("testing1") at different places, and make sure those log messages show up in the Firebug console in Firefox.
- If they don't, you have some problem that's not covered by the info in your question.
- If the ready function triggers, but facebox does not, it's a problem with facebox.
Which was it?
精彩评论