There are 3 blocks just a div so that the user can select them one by one or a few at once, and when pressed again, cancel the selection of how to implement such functionality.

  • 6
    It’s like 3,000 reputations, but you don’t know how to ask questions) Show me how you tried to solve the problem and what exactly did you have a question about - ThisMan
  • Wrap it all in a label and checkboxes, something like that ...., and ThisMan is absolutely right - Dmytryk pm

1 answer 1

Nothing complicated:

  1. Get the right divs by class
  2. Give each a click event handler.
  3. In the handler to switch the class

 const elements = document.querySelectorAll('.item') elements.forEach(i => { i.addEventListener('click', ({ target }) => { if (!target.classList.contains('disabled')) target.classList.toggle('selected') }) }) 
 body { display: flex; } .selected { border-color: blue !important; } .item { border: .4rem solid black; border-radius: .5rem; margin: 1rem; font-size: 1.5rem; padding: 1rem .5rem; width: 10rem; text-align: center; cursor: pointer; } .disabled { opacity: 0.5; cursor: default; } 
 <div class="item">Машина</div> <div class="item">Паравоз</div> <div class="item">Самолет</div> <div class="item disabled">Велосипед</div> 

  • Thank you made my day !!!!!!!! - elik
  • Ilya and how to make sure that the veospeed is not allowed to choose? - elik
  • do it like something disable - elik