Does jQuery on () support such a livequery function?

With livequery, I can do the following:

$(".focusable").livequery(function() {
   $(this).focus();
});

      

I know jQuery supports custom functions for delegates, etc., but I don't see anything that makes me think jQuery can do what livequery does in this example.

$("body").on("???", ".focusable", function() {
   $(this).focus();
});

      

Hope this makes sense.

+3


source to share


2 answers


You can use event DOMNodeInserted

:

$("body").on("DOMNodeInserted", ".focusable", function() {
   $(this).focus();
});

      



This is not supported by IE8 and older: https://developer.mozilla.org/en/DOM/DOM_event_reference

+4


source


This is currently not supported by standard jQuery. A commonly used jQuery event should be load

:

A load event is sent to an item when it and all subitems have been fully loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframe and window object.

However, it cannot be used with live

/ delegate

and most likely on

:



Note. The .live () and .delegate () methods cannot be used to detect iframe load event. The load event incorrectly flushes the parent document and event.target is not installed by Firefox, IE9 or Chrome, which should perform event delegation.

So until this is fixed you will have to stick with livequery

, they are apparently using a workaround to make this possible.

See here for more details:
http://api.jquery.com/load-event/

0


source







All Articles