Using jQuery on the console?

I will learn more about jQuery and would like to use it interactively on the JavaScript console in Chrome. Is it possible? I present something like this, but this does not work:

> use('jquery.js')
jquery loaded
> $("span").html("Hello World!")

This will cause it to "Hello World!"be inserted between the span tags and the displayed ones.

+5
source share
6 answers

There is no “use”, so of course this will not work.

You can add it to the page.

var scr = document.createElement("script");
scr.src = "http://code.jquery.com/jquery-1.9.1.min.js";
document.body.appendChild(scr);
+18
source

If you have jQuery enabled on the page where you open the console, you should be free to use it in the console.

+8
source

- <script>, jQuery, .

+4

. :-) HTML , jQuery, . .

+1

You can check out http://jsfiddle.net/ or http://codepen.io/pen/

You can still access scripts created using the chrome console, and it will be easier to share with others if you have any questions.

+1
source

If you want to use jQuery often from the console, you can easily write usercript. First, install Tampermonkey if you are in Chrome and Greasemonkey if you are in Firefox. Write a simple user pointer with a use function as follows:

var scripts = []
function use(libname){
var src;
if(scripts.indexOf(libname)==-1){
switch(libname.toLowerCase()){  
case "jquery":
src = "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js";
break;
case "angularjs":
src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js";
break;
}
}else{
console.log("Library already in use.");
return;
}
if(src){
scripts.append(libname);
var script = document.createElement("script");
script.src = src;
document.body.appendChild(scr);
}else{
console.log("Invalid Library.");
return;
}
}
+1
source

All Articles