Skip to content

[Edit] Appended section on DevTools for debugging with Dom Manipulation #7039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions content/javascript/concepts/dom-manipulation/dom-manipulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,37 @@ In the DOM tree, each part of the webpage is represented as a node. There are se
- **Modifying Content & Attributes**: Properties like `innerText`, `innerHTML`, and methods such as `setAttribute()` update content and element attributes.
- **Adding & Removing Elements**: Methods like `createElement()`, `appendChild()`, `removeChild()`, and `replaceChild()` dynamically modify the page structure.
- **Modifying Styles**: The `style` property or `classList.add()` and `classList.remove()` methods change element appearance.

## Debugging DOM Manipulation

Modern browsers ship with powerful developer tools (DevTools) that let you inspect and modify the DOM in real time while watching the JavaScript that drives those changes. Such DevTools are found in the latest releases of **Chrome**, **Firefox**, and **Safari**.

### 1. Opening the DevTools Console

| Browser | Shortcut |
| ------------- | ------------------------------------------------------------ |
| Chrome / Edge | **`Ctrl + Shift + I`** (Win/Linux) / **`⌘ + ⌥ + I`** (macOS) |
| Firefox | **`Ctrl + Shift + I`** (Win/Linux) / **`⌘ + ⌥ + I`** (macOS) |
| Safari \* | **`⌘ + ⌥ + I`** (macOS) |

<sub>\*Enable the **Develop** menu first in **Safari › Settings › Advanced**.</sub>

### 2. DevTools Main References

* **Elements / Inspector**
Browse and live‑edit the DOM tree.
*Tip:* Selecting nodes targets them on the console for manipulation. Any node highlighted can be referenced in the console with `$0`. With a node selected, **Alt + click** (Option + click on macOS) toggles expansion for all its child nodes.

* **Console**
Execute JavaScript in the page’s context and inspect results.
*Shortcuts:* `$('selector')` / `$$('selector')`, `dir($0)`, `console.log()` for quick dumps, `clear()` to wipe output.

* **Sources / Debugger**
Set breakpoints, step through code, and watch variables.

* **Network**
Inspect HTTP requests, responses, and payload sizes.

Other panels may include **_Performance_**, **_Application / Storage_**, and **_Accessibility / Lighthouse_**.

> These panels appear in every major browser’s developer tools with largely consistent names, so you can carry the same workflow between Chrome, Firefox, and Safari.