The idea here is that you pass jQuery
as $
to the inside function, making sure that the $
IS jQuery. This is commonly used to protect code that uses $
especially when using jQuery along with other libraries that use $
like mootools.
example, if you had this code in the <head>
<!--load jQuery-->
<script src="jquery.js"></script>
<script>
//"$" is jQuery
//"jQuery" is jQuery
</script>
<!--load another library-->
<script src="anotherlibrary.js"></script>
<script>
//"$" is the other library
//"jQuery" is jQuery
//out here, jQuery code that uses "$" breaks
(function($){
//"$" is jQuery
//"jQuery" is jQuery (from the outside scope)
//in here, jquery code that uses "$" is safe
}(jQuery));
</script>