πŸŽ‰ New: Top 75 PHP Interview Questions for 2026 β€” Free for all learners

change html text by javascript class name in hierarchy

P
php Guru
Β· Β· 1 min read Β·

πŸ“Œ Key Takeaways

  • change html text by javascript class name in hierarchy
  • Browser Support
  • Parameters

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”.
P
php Guru
PHP Developer & Technical Writer β€” phponline.in A seasoned PHP developer with 8+ years of experience in Laravel, MySQL, and REST APIs. Writes practical tutorials and career guides to help developers grow their skills and income. All salary data is researched from real job postings and developer surveys.
← Previous Post
Woocommerce condition if cart is empty
Next Post β†’
How to Disable a Link Using CSS Styling Links