This could be a newbie question, but here it goes. I have the following script in a file where I cannot make any changes.
$('.btn-group label:not(.active)').click(function()
{
var label = $(this);
var input = $('#' + label.attr('for'));
if (!input.prop('checked')) {
label.closest('.btn-group').find('label').removeClass('active btn-success btn-danger btn-primary');
if (input.val() == '') {
label.addClass('active btn-primary');
} else if (input.val() == 0) {
label.addClass('active btn-danger');
} else {
label.addClass('active btn-success');
}
input.prop('checked', true);
}
});
but I need to make a simple modification on it. Is there a way from another script (in another file) change the above one to look like this
$('.btn-group label:not(.active)').click(function()
{
var label = $(this);
var input = $('#' + label.attr('for'));
if (!input.prop('checked')) {
label.closest('.btn-group').find('label').removeClass('active btn-success btn-danger btn-primary');
if (input.val() == '') {
label.addClass('active btn-primary');
} else if (input.val() == 0) {
label.addClass('active btn-danger');
} else {
label.addClass('active btn-success');
}
input.prop('checked', true);
input.trigger('change'); // Added line
}
});
You should just bind a new handler:
$('.btn-group label:not(.active)').click(function()
{
$('#' + label.attr('for') + ':not(:checked)').trigger('change');
});
Beware, if class active
can switch, to handle this change, you should delegate event:
$('.btn-group').on('click', 'label:not(.active)', function(){...});