4

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

megas
  • 21,401
  • 12
  • 79
  • 130
  • Yes, I believe that is just a shorthand for $(document).ready – ebrown Apr 21 '11 at 21:10
  • what's that CDATA stuff there for? If it's there to comment-out the script from browsers that don't understand it, that hasn't been necessary since Netscape 1.0 – Alnitak Apr 21 '11 at 21:13
  • For my understanding it says to parser that data inside is only character data, not markup. And here's answer for your question http://stackoverflow.com/questions/66837/when-is-a-cdata-section-necessary-within-a-script-tag – megas Apr 21 '11 at 21:20

2 Answers2

8

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)
Daff
  • 43,734
  • 9
  • 106
  • 120
1

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

Alnitak
  • 334,560
  • 70
  • 407
  • 495