Question about $(document).ready()


#1

I was just wondering about the preferred way to use the ready function.
In the JavaScript course (which I took first because I didn't know jQuery was supposed to be easier to learn, I guess?).
Anyway, in that course, they teach you to do it slightly differently.
Instead of:

$(document).ready(function() {
    // code
});

They have you do this:

function main() {
    // code
}
$(document).ready(main);

I know, they do the exact same thing, but I was just wondering which was the preferred method for developers or is it just preference?
Personally, I like the second one, it looks much cleaner and more structured.


#2

jquery has a page about this (link), your way seems more favorable.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.