Course contentsShow
← Web Development
Lesson 2194 of 2,98240. Browser DevTools Deep DiveFree lesson

Console Utilities and $ Shortcuts

Use $(), $$(), $x() and other DevTools-only helpers for quick DOM querying.

Console Utilities and $ Shortcuts

You'll learn how to use DevTools-exclusive shortcuts like $(), $$(), and $x() to query the DOM faster than ever—right from the console.

The Console's Secret Weapon

The browser console isn't just for logging—it includes powerful built-in utilities that aren't part of JavaScript itself. These are DevTools-only helpers that give you shorthand methods for common debugging tasks, especially DOM querying.

The Dollar Sign Shortcuts

$() - Quick CSS Selector

Think of $() as your console's version of document.querySelector(). It returns the first matching element:

$('button')  // Returns first <button> element
$('.header') // Returns first element with class "header"

$$() - Multiple Elements Array

$$() works like document.querySelectorAll(), but returns a real array (not a NodeList), so you can immediately use array methods:

$$('li')           // Array of all <li> elements
$$('div').length   // Count divs directly
$$('.item').map(el => el.textContent) // Map over results

$x() - XPath Queries

For complex selections, $x() lets you use XPath expressions:

$x('//button[@disabled]')        // All disabled buttons
$x('//div[contains(text(), "Error")]') // Divs containing "Error"

Why These Matter

These shortcuts save significant typing during debugging sessions. Instead of writing document.querySelectorAll('.item') repeatedly, just type $$('.item'). They're your speed dial for DOM exploration.

Key Takeaway: DevTools provides $(), $$(), and $x() as console-only shortcuts for lightning-fast DOM querying—use them to inspect and manipulate elements during debugging, but remember they don't exist in production JavaScript code.