How do I see the state of a toggle button?
With a checkbox I can listen to "changed" event of the checkbox and do a $(this).is(":checked")
to see what state it has.
<a id="myId" class="btn" data-toggle="button"/>
But not sure how to do that with a toggle button?
Add data-toggle="buttons" to a . btn-group containing those modified buttons to enable their toggling behavior via JavaScript and add . btn-group-toggle to style the <input> s within your buttons. Note that you can create single input-powered buttons or groups of them.
Toggle button means if you need to button with two option like Play/Stop in a button at that time on first click it will be working as a play button and second time working as a stop button this is toggle button.
The data-toggle is an HTML-5 data attribute defined in Bootstrap. The advantage of using this is that, you can select a class or an id and hook up the element with a particular widget.
you can see what classes the button has..
$(this).hasClass('disabled') // for disabled states $(this).hasClass('active') // for active states $(this).is(':disabled') // for disabled buttons only
the is(':disabled')
works for buttons, but not the link btns
If you're using jQuery to intercept the click event like so...
$(this).click(callback)
you need to get creative because .hasClass('active')
doesn't report the correct value. In the callback
function put the following:
$(this).toggleClass('checked') $(this).hasClass('checked')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With