change html text by javascript class name in hierarchy

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:

ChromeEdgeFirefoxSafariOperaIE
YesYesYesYesYes9-11

Parameters

ParameterDescription
classnameRequired.
The class name of the elements.
Search for multiple class names separated by spaces like \”test demo\”.
Related Article
How to Check if a String Contains a Specific Word in Python and Java

In the vast realm of programming, strings are among the most fundamental data types. They represent text and are used Read more

JavaScript Cheat Sheet — Complete ES6 Syntax, Functions, and DOM Methods with Examples

JavaScript Cheat Sheet — Complete Syntax Reference & Examples JavaScript is the core scripting language of the web, enabling interactivity, Read more