Disclaimer: Do not try this at home
Why, if I am using jQuery, does $($)
freeze the page?
There are a few different ways of how a website can crash, including code error, plugin problems, and expired domain, among others. A website is the window of the business. It's how a company communicates with clients. So every second the site is not operational, the business is experiencing missed opportunities.
To use the Wayback Machine, head to the Wayback Machine page. Plug the full address of the web page you want to view into the box and click “Browse History”. For example, you can copy and paste this address from your browser's address bar if a web page doesn't load.
Check for Malware If disabling add-ons and updating your browser does not correct the problem, your computer may be infected with malware such as spyware or a virus. Malware can cause your browser to crash randomly or when you visit certain websites.
$($)
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).
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.
Another explanation:
$($)
.$
) to an internal ready
list.ready
list".ready
list is $
, so it calls $
.$
function as the argument to those functions.$
with $
as argument.$
function sees a function as its argument, but because the DOM is ready, it calls the function directly (there is nothing to wait for).$
function is called with $
as the argument.Now this is what I call "jQueryception."
You're calling whole jQuery library within jQuery.
More information;
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.
From jQuery 1.7.1 source code;
// HANDLE: $(function) // Shortcut for document ready } else if ( jQuery.isFunction( selector ) ) { return rootjQuery.ready( selector ); }
And
rootjQuery = jQuery(document);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With