Code snippet I found somewhere in my archive: jQuery.serializeAnything() is a jQuery Extension that serializes any element you specify, in contrast to jQuery’s builtin serialize() function which is limited to serializing form elements only.
/* @projectDescription jQuery Serialize Anything - Serialize anything (and not just forms!)
* @author Bramus! (Bram Van Damme)
* @version 1.0
* @website: http://www.bram.us/
* @license : BSD
*/
(function($) {
$.fn.serializeAnything = function() {
var toReturn = [];
var els = $(this).find(':input').get();
$.each(els, function() {
if (this.name && !this.disabled && (this.checked || /select|textarea/i.test(this.nodeName) || /text|hidden|password/i.test(this.type))) {
var val = $(this).val();
toReturn.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( val ) );
}
});
return toReturn.join("&").replace(/%20/g, "+");
}
})(jQuery);
Usage is simple: place the contents above in a .js file (jquery.serializeanything.js for example), refer to that file from your head element AFTER you referenced the jquery.js file, and use it just as you would call the serialize() function in your code: $('#myElement').serializeAnything().
Hf!
Bram.us is the technical/geeky weblog of Bram Van Damme (nicknamed Bramus!), a 28 year old geezer raised in Deinze and living in
Hi, I just came across this. Simple, convenient, and just what I needed. Thanks!
Excelent!!!
I tried $(‘#myElement’).serialize() and it did the same thing
@Florin: pre jQuery 1.3 that didn’t work
That’s really works! I used jQuery 1.3. Thanks!
Omg this is what I am looking for, thank you a lot!
Very usefull indeed!
Does not work with a multiple select box or file inputs.
let jQuery do the stuff for you…
$(‘#ingreso_detalle tbody tr:first td:first’)
.find(‘[name]:input’) //since version 1.0
.clone() //since version 1.0
.wrap(”) //since version 1.0
.serialize() //since version 1.0