Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67411

How to change text content of button when its clicked [duplicate]

$
0
0

This question already has an answer here:

So say I have this HTML

<div class="board">
  <button type="button" class="space"></button>
  <button type="button" class="space"></button>
  <button type="button" class="space"></button>
  <button type="button" class="space"></button>
  <button type="button" class="space"></button>
  <button type="button" class="space"></button>
  <button type="button" class="space"></button>
  <button type="button" class="space"></button>
  <button type="button" class="space"></button>
</div>

In javascript I have this

 const changeSpot = () => {
    this.textContent = "You clicked me!";
  }

  const spots = document.getElementsByClassName('space');

How do I make it so that changeSpot() can reference the button that is using it? I tried adding onclick="changeSpot" on the buttons however that doesnt seem to work. If it matters, the javascript functions are located in a module called gameBoard. Thanks for looking!


Viewing all articles
Browse latest Browse all 67411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>