← Back to HTML DOM
Question 177
Select First Paragraph by Tag
Select First Paragraph by Tag
Usedocument.querySelector()with the tag name "p" to select the FIRST paragraph on the page and change its text to "Updated first". Leave the second paragraph unchanged. Platform-Provided HTML (READ-ONLY):<div id="c"><p>First</p><p>Second</p></div>Steps: 1. Calldocument.querySelector("p")— it returns the first matching element. 2. Set that element'stextContentto "Updated first".
Expected Output:
<div id="c"> <p>Updated first</p> <p>Second</p> </div>
= newline. No newline after the last line.
Hints2 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.