If you want to find all HTML elements that match a specified CSS selector
(id, class names, types, attributes, values of attributes, etc), use the
querySelectorAll()
method.
This example returns a list of all
<p>
elements with
class="intro"
.
This example finds the form element with
id="frm1"
, in the forms
collection, and displays all element
values:
Example
const x = document.forms["frm1"];
let text = "";
for (let i = 0; i < x.length; i++) {
text += x.elements[i].value + "<br>";
}
document.getElementById("demo").innerHTML = text;
Try it Yourself »
The following HTML objects (and object collections) are also accessible:
If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]
Report Error
If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our
terms of use
,
cookie and privacy policy
.