Skip to content

Instantly share code, notes, and snippets.

@richardscarrott
Created April 16, 2013 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardscarrott/5395163 to your computer and use it in GitHub Desktop.
Save richardscarrott/5395163 to your computer and use it in GitHub Desktop.
jQuery.fn.serializeObject - Analogous to jQuery.fn.serializeArray and jQuery.fn.serialize but instead returns an object; useful when setting form values in Backbone.
/*global jQuery */
/*jshint bitwise: true, camelcase: true, curly: true, eqeqeq: true, forin: true,
immed: true, indent: 4, latedef: true, newcap: true, nonew: true, quotmark: single,
undef: true, unused: true, strict: true, trailing: true, browser: true */
(function ($) {
'use strict';
$.fn.serializeObject = function () {
var obj = {};
$.each(this.serializeArray(), function () {
obj[this.name] = this.value;
});
return obj;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment