Include jQuery in the JavaScript Console

Tags: ,

Is there an easy way to include jQuery in the Chrome JavaScript console for sites that do not use it? For example, on a website I would like to get the number of rows in a table. I know this is really easy with jQuery.


The site does not use jQuery. Can I add it in from the command line?


Run this in your browser’s JavaScript console, then jQuery should be available…

var jq = document.createElement('script');
jq.src = "";
// ... give time for script to load, then type (or see below for non wait option)

NOTE: if the site has scripts that conflict with jQuery (other libs, etc.) you could still run into problems.


Making the best better, creating a Bookmark makes it really convenient, let’s do it, and a little feedback is great too:

  1. Right click the Bookmarks Bar, and click Add Page
  2. Name it as you like, e.g. Inject jQuery, and use the following line for URL:

javascript:(function(e,s){e.src=s;e.onload=function(){jQuery.noConflict();console.log(‘jQuery injected’)};document.head.appendChild(e);})(document.createElement(‘script’),’//’)

Below is the formatted code:

javascript: (function(e, s) {
    e.src = s;
    e.onload = function() {
        console.log('jQuery injected');
})(document.createElement('script'), '//')

Here the official jQuery CDN URL is used, feel free to use your own CDN/version.

Source: stackoverflow