QP School
Select elements by CSS selector in JavaScript - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: JavaScript Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=6)
+--- Thread: Select elements by CSS selector in JavaScript (/showthread.php?tid=4075)



Select elements by CSS selector in JavaScript - Qomplainerz - 04-04-2023

The HTML part between the <body></body> tags looks like this:

Code:
<!-- Selecting elements by CSS selector -->

<div id="container">
  <p class="note">This is a note</p>
  <p class="note">This is another note</p>
  <p class="error">An error message</p>
</div>

The JavaScript part of the code looks like this:

Code:
// Selecting elements by CSS selector

let container = document.querySelector("#container");

document.write(container);