Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'$' already defined in Chrome?

If you type $ in console of Chrome in a plain html page without script. You would see this output

> $ < bound(selector, startNode) 

However when you do window.$ , the output is undefined,

> window.$ < undefined 

What is the $ defined here , and why can't I access it via object window ?

like image 544
Johnny Chen Avatar asked Aug 27 '15 04:08

Johnny Chen


People also ask

What is$ 0 in JavaScript?

$0 returns the most recently selected element or JavaScript object, $1 returns the second most recently selected one, and so on.

How do I change my chrome variables?

I was having the same issue, went to the 'About Google Chrome'->Help and it said I needed to restart my browser to get the latest updates. I did this, and suddenly, I can now change local variables. Simply click the variable you want to edit in the Scope Variables window, and type in your new value.

How do I find out what functions are called when a button is pressed in chrome console?

With the Chrome Developer Tools window open, click on the "Sources" tab. If you don't see anything you may need to click on the "Show Navigator" button in the upper-left corner of that tab. With the navigator open, navigate to the file where the cut() function is defined (in your case it's demo.

How do I debug a variable value in Chrome?

We can then check what values are stored in any variable at that point of time. Click F12 to open Developer Tools in Chrome. Or we can right-click and select Inspect (Ctrl+Shift+I). Go to Sources tab and expand Event Listener Breakpoints section.

What is the use of desired chrome capabilities?

Desired Chrome Capabilities class provides a set of key-value pairs to modify individual properties of web driver such as browser name, browser platform, etc. To manipulate any extensions of Chrome browser, CRX File corresponding to the extension must be extracted and must be added to Chrome Options class

What does the namespace is already defined error message mean?

The Group Policy editor detects the namespace conflict, and informs you about it with an error message. Namespace is already defined. The namespace is already defined error may be thrown on home computer systems that were upgraded from Windows 10 RTM to a newer version such as Windows 10 version 1511.

Why can't I open the Settings menu in Google Chrome?

If the settings menu doesn't open or isn't there, Chrome might have a problem. To fix, uninstall Chrome then download Chrome again from google.com/chrome and reinstall it. If you're still having problems, you might have a program installed that is changing your Google Chrome settings.

What is the use of chrome options class?

The Chrome options class is generally used in conjunction with Desired Capabilities for customizing Chrome driver sessions. It helps you perform various operations like opening Chrome in maximized mode, disable existing extensions, disable pop-ups, etc. Below example shows a way to open Chrome browser in maximized mode using ChromeOptions class.


2 Answers

$ is a local variable injected in your console from the __commandLineAPI object, via a with statement wrapping your code (that's why it's not a global variable). If you inspect it more closely (using e.g. debugger; $('*');), you'll also see that it is basically a function bound to the current window with the following source:

$: function (selector, opt_startNode) {     if (this._canQuerySelectorOnNode(opt_startNode))         return opt_startNode.querySelector(selector);      return inspectedWindow.document.querySelector(selector); } 

(defined on CommandLineAPIImpl.prototype)

like image 195
Bergi Avatar answered Oct 16 '22 18:10

Bergi


From Command Line API Reference:

The Command Line API is a collection of functions for performing common tasks with the Chrome Developer Tools. These include convenience functions for selecting and inspecting elements in the DOM...

$(selector) Returns reference to the first DOM element with the specified CSS selector.This function is an alias for document.querySelector() function.

For example:

$('body') 
like image 35
Vidul Avatar answered Oct 16 '22 18:10

Vidul