You can use jQuery addClass
, removeClass
to change how the button look and the .val()
to change its value
for example, I'll assume your are using btn-primary
in the default state, then change it to btn-danger
in the confirmation state:
$('#btn').click(function(){
// before check wich action to do
if ( $(this).hasClass('btn-primary') ){
// this is the first click
$(this).removeClass( 'btn-primary' );
$(this).addClass( 'btn-danger' );
$(this).val( 'Confirm' );
var THIS = $(this);
setTimeout(function(){
THIS.removeClass( 'btn-danger' );
THIS.addClass( 'btn-primary' );
THIS.val( 'Approve' );
}, 5000);
}
if ( $(this).hasClass('btn-danger') ){
// this is the second/confirmation click
$(this).removeClass( 'btn-danger' );
$(this).addClass( 'btn-primary' );
$(this).val( 'Approve' );
// do your action
}
});
If you are using jQueryUI you can use the switchClass function, and you can also get a nice transition of the colors :)