0

How can I change some bootstrap switch css classes dynamically if the state changes to true or false? In fact, if it is possible, appending a new class also may solve my problem. Is there any simple and useful way to do it? I tampered documentations but found nothing.

onSwitchChange event is well enough for this situation but i need some help about it.

Update

I attached an image that tells what i want to achieve.

enter image description here

hsynlms
  • 415
  • 5
  • 15
  • onSwitchChange should suffice ... what issues are you having with it ? – Aukhan Jan 12 '16 at 10:00
  • Assuma that the state is false, I need to change some elements border and background colors – hsynlms Jan 12 '16 at 10:01
  • In your switchChange callback this refers to the dom element and $(this) refers to the Jquery object. which is the input checkbox. If you have an id attribute attached with the checkbox bootstrap-switch will automatically add a class to the bootstrap switch DOM element of the form bootstrap-switch-id-{your-checkbox's-id} , you can get that element and add remove classes to it. – Aukhan Jan 12 '16 at 10:10
  • OR it also has classes for bootstrap-switch-on and bootstrap-switch-off which you could work some intelligent CSS to achieve what you attached, NO JS required. – Aukhan Jan 12 '16 at 10:12

1 Answers1

0

I think CSS is the right way to go with what you are trying to achieve, all you need to do is enclose your switch inside a parent div and then write some CSS

.parent-div .boostrap-switch-on{
  //enter styles for the ON state
  }
.parent-div .boostrap-switch-off{
  //enter styles for the OFF state
  }
Aukhan
  • 481
  • 4
  • 9