Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Inspect the Live Page in DevTools

In this video, you inspected Priya’s page as the browser is really showing it. You watched a click change it live, read why Wei’s row looks the way it does, found the listener on Wei’s Check in button, and tried a class on Sam’s row before writing any code.

Key Points

  • index.html has an empty players list. main.js built the rows when the page loaded, and every click changes them again, so the file can’t tell you what’s on the page right now. The Elements panel can, because it shows the live page.
  • The Styles pane lists the rules that match the selected element. Anything you edit in the Elements panel lasts only until the page reloads.
  • Right-click an element on the page and choose Inspect. DevTools opens on the Elements panel with that element already selected.
  • After the selected row, Chrome writes == $0, a name for that element. Press Esc to open the Console in a drawer under the Elements panel. In the Console, $0 is the element you’ve selected, so $0.dataset on Wei’s button shows DOMStringMap {playerId: 'wei', party: '2'}. $0 works only in the Console. Your files can’t use it.
  • Click Check in Wei with the Elements panel open, and two changes flash on Wei’s row. The button gains disabled, and its list item gains class="arrived". Further down the tree, the arrival bar gains style="width: 25%;". Your files didn’t change. The handler changed the live page.
  • With Wei’s list item selected, the Styles pane lists the #players li.arrived rule from style.css, which sets the light green background, #dcfce7.
  • The Computed tab shows the one value the browser used for each property. Type background in its filter box, and background-color shows rgb(220, 252, 231), the same light green. Expand it to see the rule it came from. In the Console, getComputedStyle($0).backgroundColor gives the same value.
  • The Event Listeners tab shows what an element does. With Wei’s button selected, the click group has an entry for the button, with a link to the main.js code it runs. The link opens another panel, and that’s all you need from it for now. The listener is still there after the button is disabled, but clicking a disabled button on the page doesn’t run its listener.
  • When a button does nothing, check two things in that tab: is it disabled, and does it have a listener at all?
  • You can try a change before you write it. Inspect the empty part of Sam’s row to select its list item, and $0 already holds it, with no querySelectorAll() this time. Type $0.classList.add("arrived"); in the Console. The row turns light green, and arrived appears in its start tag. The arrival bar stays put, because only the Check in handler calls showArrivals(). $0.classList.remove("arrived"); puts the row back.
  • Once a change works, write it in main.js, with the element your code holds in place of $0. This one is already there. The Check in arrow runs item.classList.add("arrived");, with item where you typed $0. Then save and reload.

Follow Along in a Blank Tab

If you don’t have Priya’s files, open a new tab, go to about:blank, and open the Console with Ctrl+Shift+J, or Cmd+Option+J on macOS. Type each entry rather than pasting it, as in the earlier lessons, because Chrome blocks a first paste into the Console as a safety measure. Press Shift+Enter between the lines of an entry.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Priya’s page lists four guests, each with a Check in button. Open index.html, though, and the players list is empty. In this video, you’ll look at the page the browser is really showing.

00:12 If you don’t have Priya’s files, the text below has a version for a blank tab. main.js built those rows when the page loaded, and every click changes them again.

00:23 So the file can’t tell you what’s on the page right now. The Elements panel can, because it shows the live page.

00:31 You’ve already read the page’s tree there, and its Styles pane, which lists the rules that match an element. Anything you edit there lasts only until the page reloads.

00:40 This time, you’ll start from something on the page and find out why it looks and acts as it does. Right-click the Check in Wei button, and choose Inspect. DevTools opens on the Elements panel with that button already selected, so you don’t hunt through the tree.

00:57 Its start tag holds the data attributes that drawPlayers gave it. After the selected row, Chrome writes equals $0, a name for this element. Press Escape, and the Console opens in a drawer under the panel.

01:13 There, $0 is whatever element you’ve selected. Type $0.dataset, and the Console shows Wei’s id and the party of 2, both as strings. $0 works only in the Console.

01:28 Your files can’t use it.

01:32 Now keep an eye on the tree, and click Check in Wei. Two changes flash on Wei’s row. The button gains disabled, and the list item above it gains the class arrived.

01:44 Your files didn’t change. The handler changed the live page, and the panel showed it as it happened.

01:50 Select Wei’s list item. The Styles pane lists the arrived rule from style.css, and it sets the light green background.

02:01 The Styles pane shows every rule that matches. Beside it, the Computed tab shows the one value the browser used for each property. Type background in its filter box.

02:13 The background color row shows an RGB value, the same light green. Expand it, and Chrome names the rule it came from.

02:21 That’s the value getComputedStyle reports. In the Console, it gives the same value for the selected element.

02:30 Styles and Computed explain how an element looks. To see what it does, select Wei’s button again and open the Event Listeners tab. Under click, it lists an entry for the button, with a link to the main.js code it runs.

02:44 The link opens another panel, and that’s all you need from it for now. The button is disabled now, and its listener is still there. Clicking a disabled button on the page doesn’t run its listener.

02:57 So when a button does nothing, check two things here: is it disabled, and does it have a listener at all?

03:06 You can also try a change here before you write it. Right-click the empty part of Sam’s row, and choose Inspect. Sam’s list item is selected, so $0 already holds it, with no querySelectorAll this time.

03:19 In the Console, add the class arrived to $0’s class list. The row turns light green, and arrived appears in its start tag. The bar stays put, because only the Check in handler updates it.

03:32 Remove it, and the row is back to normal.

03:35 Once a change works, write it in main.js, with the element your code holds in place of $0. This one is already there. The Check in arrow adds arrived to item.

03:47 Then save and reload.

03:50 The Elements panel shows the live page, not your file. Inspect finds an element. Styles and Computed say why it looks that way, and Event Listeners says what it does.

04:03 Next, in Exercise: Check Guests In, you’ll help Priya check her guests in and confirm each change in the Elements panel.

Become a Member to join the conversation.