Skip to content

Comment on Faster than jQuery(document).ready() - Wait Until Exists

Comments

Does someone have a really good example of where this would be useful? The description is basically, "When this element exists, do something" but what is the something you'd do? If it's styling, that should be done in CSS. If it's event handlers, that can be done with `.live()` or `.delegate()`.

I'd also like to see some benchmarks to back up the assertion that this is faster. The DOM modification events are generally accepted as slow and it seems like this is leaving a handler attached for the duration of the page's existence.

some UI stuff could benefit from this: things like turning a list into an accordion. (Normally there is at least a little work to be done to ensure you don't get a flash of unstyled/unscripted content, if this fires fast enough you could avoid that)

OP here: neither .live() or .delegate() do functions when an element comes to existence, those just bind events.

I used this a lot when developing a Chrome extension for Facebook because i can identify when an HTML element is created via ajax.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.