Skip to content

Instantly share code, notes, and snippets.

@reneoelke
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save reneoelke/09b0fd4087ae78c4b5fa to your computer and use it in GitHub Desktop.

Select an option

Save reneoelke/09b0fd4087ae78c4b5fa to your computer and use it in GitHub Desktop.
jQuery Bookmarklet for Chrome
javascript:
var jQueryVersion = "2.1.1";
if (typeof(jQuery) == "undefined") {
var jQueryScript = document.createElement('script');
jQueryScript.type = "text/javascript";
jQueryScript.src = "//ajax.googleapis.com/ajax/libs/jquery/" + jQueryVersion + "/jquery.min.js";
jQueryScript.onload = function() {
jQuery.noConflict();
console.log("jQuery " + jQuery.fn.jquery + " loaded successfully.");
};
jQueryScript.onerror = function() {
delete jQuery;
console.error("Error while loading jQuery!");
};
document.getElementsByTagName('head')[0].appendChild(jQueryScript);
} else {
if (typeof(jQuery) == "function") {
console.info("jQuery (" + jQuery.fn.jquery + ") is already loaded!");
} else {
console.info("jQuery is already loading...");
}
}
@reneoelke
Copy link
Author

Here are the steps to create this bookmarklet in Chrome:

  1. Open source code in raw mode
  2. If bookmark bar isn't shown then show it with Shift + Cmd + b / Shift + Ctrl + b
  3. Select all the source code with Cmd + a / Ctrl + a
  4. Drag & Drop the selected source code to the bookmark bar
  5. Right click on the new icon, select Edit ... and give it a name like jQuery 2.1.1

Ready. Just open the javascript console with Alt + Cmd + j / Alt + Ctrl + j, click on the bookmarklet and have fun (i.e. jQuery.get();). ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment