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.
1 answer
Nothing complicated:
- Get the right divs by class
- Give each a click event handler.
- 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
|
labeland checkboxes, something like that ...., and ThisMan is absolutely right - Dmytryk pm