Why function $ (function () is always executed

I wonder why it $(function () {}runs all the time. function test(0no. what's the difference between the two?

+5
source share
2 answers

jQuery extreme shorthand tends to trick the eye sometimes.

Look at the design: a function is called with a name $, with the function as an argument. This is not the same as defining a function for later use, for examplefunction test() { .... }

$is a jQuery shortcut for a finished document. The function passed to it will be launched after the document is loaded.

+6
source

This is a short form for the finished document.

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

,

+5

All Articles