What is the difference between this?
$("form").serialize();
and this?
var theForm = $("form");
$(theForm[0]).serialize();
How do you get the second sample to serialize like the first one?
asked Oct 1, 2011 at 21:26
user366735
2,2133 gold badges22 silver badges20 bronze badges
3 Answers 3
try this:
var theForm = $("form");
theForm.eq(0).serialize();
answered Oct 1, 2011 at 21:28
Ilia Choly
18.6k14 gold badges95 silver badges166 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
First one selects all forms and serializes all form fields.
Second one selects form fields from FIRST form and serializes them
answered Oct 1, 2011 at 21:28
genesis
51.1k20 gold badges99 silver badges127 bronze badges
1 Comment
user366735
the problem is the second one doesn't serialize the first form.
Or you could use in one line:
$("form:first").serialize();
Comments
lang-js