How to refactor jquery
- by Pierce McGeough
I have buttons on the page that will activate and deactive settings. the Ids are the same bar their prefix e.g I have '#rl-activate', '#rl-deactivate', '#cl-activate', '#cl-deactivate' Is there a way to refactor this code so i am not doing it for every button on the page.
// rl activate
$('#rl-activate').click(function(){
$('#rl-activate').hide();
$('#rl-deactivate').show();
$('#rl').val(50).prop('selected', true);
$('#rl').prop('disabled', false).trigger('liszt:updated');
displayCPM();
newPrice();
checkSettings();
});
// rl deactivate
$('#rl-deactivate').click(function(){
$('#rl-deactivate').hide();
$('#rl-activate').show();
$('#rl').prop('disabled', true).trigger('liszt:updated');
$('#rl').val('').trigger('liszt:updated');
displayCPM();
newPrice();
checkSettings();
});
So for the next one all that changes will be the rl to cl to bm etc