代码示例:(标识:jsck_document_queryselector_p)
<!DOCTYPE html>
<html>
<body>
<h1>Document 对象</h1>

<h2>querySelector() 方法</h2>

<h3>为第一个 p 元素添加背景颜色:</h3>

<p>这是一个 p 元素。</p>
<p>这是一个 p 元素。</p>

<script>
document.querySelector("p").style.backgroundColor = "red";
</script>

</body>
</html>
运行结果: