(function($){ $.fixieAjaxForm = function(onSuccess) { // $('form').fixieAjaxForm() // $(this) == $('form') inside this function $(this).ajaxForm(function(str) { var data = $.parseJSON(str); $(this).find('label.error').removeClass('error'); if (data.errors.length === 0) { $(this).resetForm(); onSuccess(data); } else { $.each(data.errors, function(){ $('label[for='+ this[0]+']').addClass('error'); }); } }) } })(jQuery);