Get All DOM Tags

Easy
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Get All DOM Tags

Approach

Traverse the tree recursively, adding each node's tag name (lowercased) to a Set to collect unique values. Sort the Set into an array for the final result. Extend with a counting variant that uses an object to tally occurrences of each tag.

Complexity Analysis

Time
O(n) where n is the number of nodes
Space
O(u) where u is the number of unique tags

Pattern

Tree Traversal Collection

Why It Works

A Set automatically deduplicates tag names during traversal, and lowercasing before insertion ensures case-insensitive uniqueness across mixed-case DOM trees.

Updated Feb 2026