← Back to HTML DOM
Question 137
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>
Topics:
HTML DOM
Code Editor
1
Tab to indent · Ctrl+Enter to run · 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.