Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command for loading jQuery on Google Chrome inspector?

I remember seeing that there was a specific command you could put on Google Chrome's inspector console for it to load jQuery and allow you to execute jQuery commands.

However, I cannot remember which command it was, and searching online only brings me unrelated results.

Anyone knows which is that command?

Thanks!

EDIT: Years later I had realized that I was asking for the $$ function in the console. However, this is not jQuery but provides a similar selector option, most likely a shorthand for document.querySelectorAll. The answers here address adding jQuery for real, with all of its functionality.

like image 693
Alpha Avatar asked Mar 08 '12 21:03

Alpha


People also ask

How do I get jQuery in Chrome?

Load jQuery into your current page by copying and pasting the following code into your Chrome Console. var jqry = document. createElement('script'); jqry. src = "https://code.jquery.com/jquery-3.3.1.min.js"; document.

How do I know if jQuery is loaded?

You can just type window. jQuery in Console . If it return a function(e,n) ... Then it is confirmed that the jquery is loaded and working successfully.

How do I use console in Chrome?

To open the developer console in Google Chrome, open the Chrome Menu in the upper-right-hand corner of the browser window and select More Tools > Developer Tools. You can also use Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux).


1 Answers

You mean, a script to load jQuery in an arbitrary page? I have constructed the following cross-browser bookmarklet for this purpose:

javascript:if(!window.jQuery||confirm('Overwrite\x20current\x20version?\x20v'+jQuery.fn.jquery))(function(d,s){s=d.createElement('script');s.src='https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.js';(d.head||d.documentElement).appendChild(s)})(document); 

It detects whether jQuery exists. If it does, a confirmation dialog appears, in which the current version is shown, so that you can decide whether it's OK to overwtite the existing jQuery object.

Currently, jQuery 1.8 is loaded from a CDN over SSL.

  • If you want to load a different version, replace '1.8' with e.g. '1.7.1'.
  • If you want to load a compressed version, replace jquery.js with jquery.min.js.
  • If you don't mind loading jQuery over http:, Google's CDN can be replaced with:
    • http://code.jquery.com/jquery.js - Latest version
    • http://code.jquery.com/jquery-latest.js - Latest version
    • http://code.jquery.com/jquery-1.8.0.js - Version 1.8

To save you time from editing, here's the same bookmarklet as the top of the answer, but getting the latest version (instead of a fixed one) from http://code.jquery.com/:

javascript:if(!window.jQuery||confirm('Overwrite\x20current\x20version?\x20v'+jQuery.fn.jquery))(function(d,s){s=d.createElement('script');s.src='http://code.jquery.com/jquery.js';(d.head||d.documentElement).appendChild(s)})(document); 

Note: Having the latest version is nice, but don't be surprised when jQuery "behaves weird" (=updated).

like image 185
Rob W Avatar answered Sep 20 '22 02:09

Rob W