Is there a jQuery equivalent to do the following:
$(document).ready(function() {
for an element:
$(a).ready(function() {
I have content in an updatepanel and I am calling jQuery UI's .button() on some anchor elements. After the updatepanel refreshed, the anchors are rerendered and lose the UI styling.
I already know how to detect the end of an ajax request using .NET AJAX's add_endrequest(handler), but was hoping for a neater solution using jQuery.delegate.
e.g.
$('body').delegate('#mybutton', 'load', (function(){ //this doesnt work... }
you can easily track on load for any element in the web page.
for more details see this thread : jQuery How do you get an image to fade in on load?
Are you are trying to solve the wrong problem? IF it is just style: Try to add instead, css in the header so that the update does not impact the style. Note: Not exactly sure on your selectors based on your question for these examples.
OR
If you indeed need some event management you should be able to use the delegate using context. see notes here: http://brandonaaron.net/blog/2010/03/4/event-delegation-with-jquery
or with a chain
Now for the real answer, since you have access to the event you can add it directly to your page with the pageLoad function; Add this:
Update in 2018, You can use new MutationObserver API for this, here is a plugin just for that:
the limitation is that it only work for base use of jQuery with string as CSS selector.
If you don't need the same name as build in ready you can use different name and remove
ready.call(self, callback);
.element rendered state can be detected using animation event as bellow, Example: TAB-C's image box will get updated in size from it's parent node
elementReady: a jQuery plugin
If I understand your requirement correctly, one way to do this is with the Live Query plug-in.
For example:
Update: Since the DOM changes are not running through jQuery, unfortunately livequery doesn't see them. I mulled over this issue before and considered a polling-based solution in this answer.
Update: Polling is kind of ugly, but if there's really no other alternative, here's a polling-based solution that uses a jQuery "dummy" manipulation to make livequery "see" the change. You'd only want to consider something like this as a last resort -- if there's no option to tie into a callback method.
First, set up livequery watching the container where the updates will occur:
And then use
setInterval()
, here wrapped in a convenience function:So you can have:
Here's a working example. Click the button to add new DOM elements without jQuery, and you'll see they get picked up (eventually) and restyled by livequery. Not pretty, but it does work.