Live data from Hacker News

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

javascriptisawesome.blogspot.com

41–48 of 48 posts

Re: Faster than jQuery(document).ready() - Wait Until Exists

#41
post #11

Why are you comparing this to `jQuery(document).ready()`? Apples and oranges. You say it’s faster, but fail to provide any numbers / a jsPerf test case. I’m sure it’s faster to execute `waituntilexists()` initially , but if you take into account it uses an 5ms interval in which it traverses the DOM for the same elements over and over again until they’re finally found, it seems it probably has a negative impact on per…

OP here. The 5ms interval is only used on old versions of Internet Explorer.

It uses getElementById to traverse the DOM and it is said to be the faster selector in javascript.

Re: Faster than jQuery(document).ready() - Wait Until Exists

#42

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 generall…

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.

Re: Faster than jQuery(document).ready() - Wait Until Exists

#43

Quick remarks : * I could test it myself, but I expected to have in the article detailed information on the different possible states the document can have when my callback is called. The questions I know the answer when waiting for the whole document to be loaded : Is it half loaded ? What is the DOM state ? Is completely loaded ? If not, have the document JavaScript code been entirely ran ? and so on. This kind of…

1) The dom state is that everything inside the HTML element that you were waiting for already exists when the function is executed.

2) When i am writing javascript is very common for me to use the global object (window) as the context; so in my case is not a good idea to use the HTML element as context by default.

Re: Faster than jQuery(document).ready() - Wait Until Exists

#45
post #40
post #13

Earlier quoted context omitted.

this is why we need vote counts to be displayed again.

I am the OP; i just removed the background... but is going to be back! (as soon as i figure out a way to make it consume less CPU... probably using canvas)

I came late; what used to be there?

Re: Faster than jQuery(document).ready() - Wait Until Exists

#46
post #45
post #40

Earlier quoted context omitted.

I am the OP; i just removed the background... but is going to be back! (as soon as i figure out a way to make it consume less CPU... probably using canvas)

I came late; what used to be there?

Just some scene of an anime.
Post reply on HN