Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entry point for jquery document

Tags:

jquery

In every JQuery tutorial the entry point is always like this:

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

But in sdoc project it has different entry point as for my novice's view. Here's the code snippet and there the full file:

<script type="text/javascript" charset="utf-8">
    //<![CDATA[
    function placeholder() {
        ...
    }
    $(function() {
       placeholder();
       ...
    })
    //]]>
</script>

The question: Is $(function()..) the entry point for jquery script? And if it does why it differ from traditional approach? Thanks

like image 480
megas Avatar asked Jan 20 '23 22:01

megas


2 Answers

It's the same. From the jQuery documentation for .ready():

All three of the following syntaxes are equivalent:

$(document).ready(handler)
$().ready(handler) (this is not recommended)
$(handler)
like image 71
Daff Avatar answered Jan 27 '23 21:01

Daff


$(function() { ... }) is just short hand for $(document).ready(function() { ... })

like image 21
Alnitak Avatar answered Jan 27 '23 22:01

Alnitak