Question about $(document).ready()


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

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.


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


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