JSFiddle - React, Tailwind, and code Playground
HTML
<div class="testClass">
A div with class="testClass".
</div>
<div class="testClass">
The second div with the same class name.
</div>
<p class="testClass">
A paragraph with testClass
</p>
<button onclick="testFunction();">Alert the content of the first testClass</button>
<script>
function testFunction() {
var x = document.getElementsByClassName("testClass");
alert(x[0].innerHTML);
}
</script>