Jan 01
JQuery Tip #1 : $(function() { });
Hey! A quick tip about JQuery that I don't feel like writing a giant tutorial about (besides, you're probably still making your way through the last two).
Suppose you want to execute a function only when the DOM is loaded, but not the actual document. You could use an onload= handler, which is very glitchy and only works when the document is COMPLETELY done loading, not just the structure. That's not good! Why don't we use some jquery goodies to help out instead?
- Code:
$(function() {
And that's all you need. Anything after that and before a }); will be executed as soon as the DOM is created and stabilized.
This is an important function and is both useful and versatile. Don't forget it!
I recently wrote a code, zEdit; I'm sure most of you know this, as I bet more than half of my posts are in that topic, and that's where you probably got the link to this blog. Well, IE was not happy with zEdit. It kept erroring out Operation Aborted. Generation Studio pointed out that I was modifying the DOM before it was fully created, which as most of us know, IE has a problem with (along with too many semicolons and the odd mood swing). Thanks to the $(function(){ function, I was able to execute the code only when IE was done chewing up HTML. Yay!
-
Comment by Brian, Jan 2 2008, 09:38 AM
Thanks for the very useful blog Choco

- Add new comment:
10:48 AM Dec 8