M
M
Mikhail Petrov2016-03-28 10:05:14
JavaScript
Mikhail Petrov, 2016-03-28 10:05:14

How to change class on checkbox click?

Good afternoon, tell me please.
I want to wrap the checkboxes in a Lable, how to make it so that when the checkbox is selected, the lable changes from the default label-primary to label label-success and back if the selection is removed from the checkbox. Thank you.

<span class="label label-primary"><input type="checkbox">Не выделено</span>
<span class="label label-success"><input type="checkbox">Чекбокс выделено</span>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Belyaev, 2016-03-28
@bingo347

Can be done on pure css, more precisely on sass with the sass version of the bootstrap
connected through the checkbox, you can influence neighboring elements
codepen.io/bingo347/pen/EKXdPB

M
Mikhail Petrov, 2016-03-28
@fatklass

or mb lable itself can be made as a checkbox when one color is not selected, another is selected.

D
devstudent, 2016-03-28
@devstudent

If the class change is necessary for styling, then the :checked pseudo-class can be
used
css for the selected checkbox
input[type="radio"]:checked + span {
// styles
}
If for other purposes, then through javascript or php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question