<h1 class="title">Hello!</h1>

<script>
  function getTitle() {
    const title = document.querySelector(".title") 
    alert(`Found h1 with class ${title.className}``)
  }
</script>
<button onclick="getTitle()">Get element by class</button>

<div>
  <a href="https://www.bytesized.xyz/javascript-get-element-by-class">Read the post -></a>
</div>
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.