I’m trying to learn DRY coding and wondering how to do this sort of thing with a lot less code.
ie I have something like this:
var option_shipping = $('#option_shipping div.selected .tag').text(),
option_payment = $('#option_payment div.selected .tag').text();
if(option_shipping.length < 1) {
error = 1;
$('.option_shipping_wrap').addClass('attention');
}
if(option_payment.length < 1) {
error = 1;
$('.option_payment_wrap').addClass('attention');
}
What is the most minimal way something like this can be done?
if you using jQuery, you can make a little plugin for your needs:
then you can call it anywhere, and enjoy the advantages of chaining: