Search code examples
jqueryfirefoxfirefox-developer-tools

How can I use jQuery in the Firefox Scratchpad?


How can I go about using jQuery in the Firefox Scratchpad?
I have Firefox v54.0.1.

I googled it and found some articles mentioning how the Firefox Scratchpad had jQuery built-in but those articles were written back when the Scratchpad was first released.

http://www.davidhayden.me/blog/jquery-and-javascript-development-using-firefox-scratchpad

https://hacks.mozilla.org/2013/11/reintroducing-the-firefox-developer-tools-part-2-the-scratchpad-and-the-style-editor/

I originally just tried the jQuery code and when it wasn't working I threw in the CDN for it.. I was desperate..

Any suggestion is appreciated!
Thanks!

Firefox Scratchpad Screenshot

EDIT: (Added Dave's suggestion)

Firefox Scratchpad Screenshot 2


Solution

  • You should be able to inject a script element by adding this code at the beginning of the scratchpad. Additionally you need to wait for it to load, you you'll need to run your code in a callback

    let jq = document.createElement("script");
    jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js";
    jq.onload = function() {
      //your code here
    };
    document.body.appendChild(jq);