Switch toggle jquery functions


Topic: Switch toggle jquery functions

salmanfazal01 pro asked 6 years ago

How do I get/perform the following data using jquery functions:

  1. Toggle the switch element to on/off
  2. run a function when switch is toggled off

salmanfazal01 pro answered 6 years ago

Just to answer my questions:

  1. "$('#id input:checkbox').prop('checked', true);"
  2. "$('#id input[type="checkbox"]').on('change', function() { if( id != "on" {}) })"

Krzysztof Wilk staff answered 6 years ago

Hello!

The state of switch (on/off) depends on "checked" attribute of input. When input has this attribute, it's on, when input doesn't have it - it is off. So you have to use jquery to add/remove this attribute. For the second subpoint I think you can make a condition, that'll be checking if input has "checked" attrib or not and if yes, It run code you want.


salmanfazal01 pro commented 6 years ago

And how do I change toggle the switch button? I think for Bootstrap it's ".bootstrapSwitch();" but I can't find anything for this one.

".click()" doesnt work for me either for some reason


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.8.0
  • Device: Chrome
  • Browser: Chrome
  • OS: Chrome
  • Provided sample code: No
  • Provided link: No
Tags