Skip to content

Instantly share code, notes, and snippets.

@bjrn
Created July 29, 2011 10:34
Show Gist options
  • Save bjrn/1113589 to your computer and use it in GitHub Desktop.
Save bjrn/1113589 to your computer and use it in GitHub Desktop.
Zepto version of $.fn.serializeForm used in http://maccman.github.com/spine.tutorials/form.html. Requires Zepto > 0.6 that $.fn.serializeArray()...
// jQuery version of the same function.
// Zepto doesn't provide $.each, but rather uses the native Array.forEach() function
$.fn.serializeForm = function(){
var result = {};
$.each($(this).serializeArray(), function(i, item){
result[item.name] = item.value;
});
return result;
};
$.fn.serializeForm = function(){
var result = {};
$(this).serializeArray().forEach(function(item, i){
if (item.name.length){
result[item.name] = item.value;
}
});
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment