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.htmlhas an empty players list.main.jsbuilt 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,$0is the element you’ve selected, so$0.dataseton Wei’s button showsDOMStringMap {playerId: 'wei', party: '2'}.$0works 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 gainsclass="arrived". Further down the tree, the arrival bar gainsstyle="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.arrivedrule fromstyle.css, which sets the light green background,#dcfce7. - The Computed tab shows the one value the browser used for each property. Type
backgroundin its filter box, andbackground-colorshowsrgb(220, 252, 231), the same light green. Expand it to see the rule it came from. In the Console,getComputedStyle($0).backgroundColorgives the same value. - The Event Listeners tab shows what an element does. With Wei’s button selected, the
clickgroup has an entry for the button, with a link to themain.jscode 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
$0already holds it, with noquerySelectorAll()this time. Type$0.classList.add("arrived");in the Console. The row turns light green, andarrivedappears in its start tag. The arrival bar stays put, because only the Check in handler callsshowArrivals().$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 runsitem.classList.add("arrived");, withitemwhere 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.