Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery serialize / serializeArray from an element that is not a form

Tags:

jquery

I haven't found a concrete answer as to whether this is possible, but it seems like it should be...

I would like to serialize all the input elements contained in a div. I can't use a form, because it would be nested within another form. I would then get the values and post them via ajax.

Here is the jsFiddle example I am playing with:

http://jsfiddle.net/9uyz5/

If I change the root to a it works as expected.

Thanks for your help.

I've modified the jsfiddle from this other question:

https://stackoverflow.com/a/1186309/25020

like image 624
B Z Avatar asked Mar 06 '12 17:03

B Z


2 Answers

you need to serialize all the inputs inside your container, not the actual container itself. so:

$('div :input').serialize() 
like image 65
Omer Bokhari Avatar answered Sep 28 '22 04:09

Omer Bokhari


Try this, to get all.

$('#divID *').serialize() 
like image 42
tiru Avatar answered Sep 28 '22 05:09

tiru