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

change html text by javascript class name in hierarchy

P
php Guru
Β· May 8, 2023 Β· 1 min read Β· Updated May 8, 2023

πŸ“Œ Key Takeaways

  • change html text by javascript class name in hierarchy
  • Browser Support
  • Parameters
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”.
P
php Guru
← Previous Post
Woocommerce condition if cart is empty
Next Post β†’
How to Disable a Link Using CSS Styling Links

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove your humanity: 7   +   9   =