πŸŽ‰ New: Top 75 PHP Interview Questions for 2026 β€” Free for all learners
Beginner ⏱ min read πŸ”„ Updated
Home β€Ί

Advertisement

Example

<!DOCTYPE html>
<html>
<body>
<h1>The Document Object</h1>
<h2>The querySelectorAll() Method</h2>

<p>Add a background color all elements with class=”example”:</p>
<h2 class=”example”>A heading</h2>

<div class=”asdf”><p class=”example”>A paragraph.</p> </div>

<script>
const tinaicon = document.querySelectorAll(“.asdf .example”);
for (let i = 0; i < tinaicon.length; i++) {
tinaicon[i].innerHTML = “your text here”;
}
</script>

</body>
</html>

output

Browser Support

document.getElementsByClassName()Β is a DOM Level 1 (1998) feature.

It is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 9-11

Parameters

Parameter Description
classname Required.
The class name of the elements.
Search for multiple class names separated by spaces like “test demo”.

# Summary

Here is what you've learned in this lesson:

  • Browser Support
  • Parameters
πŸš€
Next up: How to Check if a String Contains a Specific Word in Python and Java

Continue to the next lesson and learn more about How to Check if a String Contains a Specific Word in Python and Java.

Start Next Lesson β†’

← Previous Post
Woocommerce condition if cart is empty
Next Post β†’
How to Disable a Link Using CSS Styling Links