Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jQuery at Console?

I'm learning more about jQuery and would like to use it interactively at the JavaScript console in Chrome. Is that possible? I envision something like this, but it doesn't work:

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

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

like image 805
Clint Laskowski Avatar asked Mar 15 '13 13:03

Clint Laskowski


4 Answers

There is no "use" so of course it will not work.

You can append it to a page.

var scr = document.createElement("script");
scr.src = "http://code.jquery.com/jquery-1.9.1.min.js";
document.body.appendChild(scr);
like image 197
epascarello Avatar answered Nov 06 '22 07:11

epascarello


If you have jQuery included in the page that you have the console open on you should be free to use it in the console.

like image 27
Wryte Avatar answered Nov 06 '22 08:11

Wryte


The simpliest way to do this, is to edit the header of the page and add a <script> tag pointing to jQuery. Then you will be able to execute the code in your console.

like image 4
Kru Avatar answered Nov 06 '22 06:11

Kru


Never mind. Figured it out :-) I created a simple HTML file that loaded jQuery and then went into the console. This works for me.

like image 1
Clint Laskowski Avatar answered Nov 06 '22 07:11

Clint Laskowski