tag:blogger.com,1999:blog-865923359735383241.post3202636915859405749..comments2023-10-29T07:27:09.012-06:00Comments on Ccna final exam - java, php, javascript, ios, cshap all in one: Why does $($) crash my page?Unknownnoreply@blogger.comBlogger3125tag:blogger.com,1999:blog-865923359735383241.post-2923060203727298022012-04-08T20:35:57.472-06:002012-04-08T20:35:57.472-06:00$ is an alias to the jQuery factory function.The j...$ is an alias to the jQuery factory function.<br><br>The jQuery factory function, when passed a function as first param, runs that function at document.ready and passes jQuery as the first parameter to it.<br><br>Thus you end up with a infinite recursion starting when document.ready is reached.Tips For Allhttp://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-85859499003126005202012-04-08T20:35:56.791-06:002012-04-08T20:35:56.791-06:00Now this is what I call "jQueryception."...Now this is what I call "jQueryception."<br><br>You're calling whole jQuery library within jQuery.<br><br>More information;<br><br>When you call "$" (defined as jQuery core function by jQuery library) it initializes the jQuery and tries to call the defined function if it has one. When you actually call "$($);" you'll be calling jQuery inside jQuery and it'll be calling jQuery again and again.<br><br>From jQuery 1.7.1 source code;<br><br> // HANDLE: $(function)<br> // Shortcut for document ready<br> } else if ( jQuery.isFunction( selector ) ) {<br> return rootjQuery.ready( selector );<br> }<br><br><br>And<br><br>rootjQuery = jQuery(document);<br><br><br>As you can see, when you call $($); it tries to call jQuery with the name of your function and if you call it with jQuery again same thing will happen endlessly as I've explained before.Tips For Allhttp://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-12230967568875864992012-04-08T20:35:55.945-06:002012-04-08T20:35:55.945-06:00$($) is a shortcut for $(document).ready($). So, i...$($) is a shortcut for $(document).ready($). So, it will run the function (when the DOM is ready or directly when this is already the case).<br><br>The function passed to .ready is passed the jQuery function for convenience (especially useful when you're in noConflict mode). So, $($) will call $ with $ as argument - and everything will happen again, which is endless recursion.<br><br><br><br>Another explanation:<br><br><br>You call $($).<br>jQuery adds the function argument ($) to an internal ready list.<br>Some time later, jQuery sees that the DOM is ready and thinks: "Let's call all functions in the ready list".<br>The only function in the ready list is $, so it calls $.<br>jQuery sees it should pass the $ function as the argument to those functions.<br>It calls $ with $ as argument.<br>The $ function sees a function as its argument, but because the DOM is ready, it calls the function directly (there is nothing to wait for).<br>The function is called with $ as the argument.<br>Everything happens again since step 7 applies.Tips For Allhttp://www.blogger.com/profile/11557173689529910046noreply@blogger.com