JSFiddle - React, Tailwind, and code Playground

by bemuse

HTML

<div>
  <input type="button" value="밥먹기">
  <span></span>
</div>
<div>
  <input type="button" value="씻기">
  <span></span>
</div>
<div>
  <input type="button" value="강의듣기">
  <span></span>
</div>

JavaScript

const buttons = document.querySelectorAll(`div > input[type="button"]`)
const texts = document.querySelectorAll(`div > span`)

const onClickButton = (idx) => {
	const text = texts[idx]
	text.innerText = 'Strike'
}

buttons.forEach((button, idx) => {
	button.addEventListener('click', () => onClickButton(idx))
})