JSFiddle - React, Tailwind, and code Playground

HTML

<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div class="btn-group">
      <button class="btn">버튼 1</button>
      <button class="btn">버튼 2</button>
    </div>
    <div class="container">
      <div class="box">박스1</div>
      <div class="box">박스2</div>
    </div>
  </body>
</html>

CSS

* {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
      body {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        height: 70vh;
      }
      .btn {
        padding: 10px;
        background-color: #ffb142;
        border: none;
        border-radius: 10px;
        font-size: 1.5rem;
        color: #fff;
        cursor: pointer;
        transition: 0.5s;
      }
      .btn.clicked {
        background-color: #34ace0;
      }
      .container {
        display: flex;
        margin-top: 20px;
      }
      .box {
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 10px;
        width: 200px;
        height: 200px;
        background-color: #218c74;
        font-size: 1.5rem;
        color: #fff;
        transition: 0.5s;
      }
      .box.clicked {
        background-color: #ff793f;
      }

JavaScript

const btnGroup = document.querySelector(".btn-group");
      const btns = document.querySelectorAll(".btn");
      const boxes = document.querySelectorAll(".box");
      let currentItems = [];

      //data-index 설정
      for (let i = 0; i < btns.length; i++) {
        btns[i].dataset.index = i;
        boxes[i].dataset.index = i;
      }

      const btnClickHandler = (e) => {
        const targetElem = e.target;
        const targetIdx = targetElem.dataset.index;
        //currentElems에 값이 있으면 clicked 제거
        if (currentItems) {
          currentItems.forEach((currentItem) => {
            currentItem.classList.remove("clicked");
          });
        }
        //targetElem의 class가 btn이면 같은 index를 가진 btn과 box에 clicked 추가
        if (targetElem.classList.contains("btn")) {
          btns[targetIdx].classList.add("clicked");
          boxes[targetIdx].classList.add("clicked");
          //클릭된 btn과 같은 인덱스를 가진 btn과 box를 currentElems에 할당
          currentItems = [btns[targetIdx], boxes[targetIdx]];
        }
      };
      btnGroup.addEventListener("click", btnClickHandler);