Reputation: 47
I am using Bootstrap & Jquery.
How to change class of inactive after toggled
HTML Code
<div class="btn-group btn-toggle">
<button class="btn btn-default">Active</button>
<button class="btn btn-danger active">Inacive</button>
SCRIPT
$(document).ready(function(){
$('.btn-toggle').click(function() {
$(this).find('.btn').toggleClass('active');
if ($(this).find('.btn-danger').size()>0) {
$(this).find('.btn').toggleClass('btn-success');
$(this).find('.btn').addClass('btn-default');
}
else if ($(this).find('.btn-success').size()>0) {
$(this).find('.btn').toggleClass('btn-danger');
addClass() seems not working..
Upvotes: 2
Views: 1514
Reputation: 88
I understand that you are trying to disable and enable buttons on certain actions. Here is how I got it:
This is the button on my form:
<button type="submit" class="btn btn-primary">Compute</button>
Add this line when you click on the button, in my case I am disabling the button once the form is submitted:
$('button', form).addClass('disabled').text("Computing...");
Enable back once you are done:
$('button', form).removeClass('disabled').text("Compute");
Hope this helps!
Upvotes: 1