Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You don't have to use $(document).ready() anymore

As far as I know, this was always the case. The reason people use $(document).ready() is that it feels more correct, is more consistent. jQuery() supports three distinct behaviors:

    $(function)   => jQuery(document).ready(function)
    $(objects)    => Wrap objects with jQuery functionality
    $("selector") => Find objects, and wrap them with jQuery functionality

One of these is not like the others.


Actually, there are four!

    $("<tag>") => Make a DOM element and wrap it
This wild overloading of $ is one of the things I find hard to deal with in jQuery.


Doh, that's right, and it is one of the coolest and most fun to abuse features of jQuery.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: