I'm looking for a better way of writing this repetitive jQuery function:
(function($) {
var mobileAmount = 300;
$('#_100').click(function() {
$('*').removeClass('-amount-active');
$('#_100').addClass('-amount-active');
mobileAmount = 100;
});
$('#_200').click(function() {
$('*').removeClass('-amount-active');
$('#_200').addClass('-amount-active');
mobileAmount = 200;
});
$('#_300').click(function() {
$('*').removeClass('-amount-active');
$('#_300').addClass('-amount-active');
mobileAmount = 300;
});
...
})( jQuery );
There is a number of amount buttons and each time one is clicked it receives the active class for styling and updates the mobileAmount variable.
id
attribute. I think however that the question itself is not really on-topic (cfr: help center) \$\endgroup\$