← Back to HTML DOM
Question 181
Create a Link Element
Create a Link Element
Create a new<a>element withhref"https://example.com" and text "Visit", then append it inside the nav with id="nav". Platform-Provided HTML (READ-ONLY):<nav id="nav"></nav>Steps: 1. Create the anchor withdocument.createElement("a"). 2. Set its href withsetAttribute("href", "https://example.com")and itstextContentto "Visit". 3. Append it withnav.appendChild().
Expected Output:
<nav id="nav"> <a href="https://example.com">Visit</a> </nav>
= newline. No newline after the last line.
Hints4 available
Sign in to use hintsTopics:
HTML DOM
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (clog, fn, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.