user366735
user366735

Reputation: 2203

jQuery Object Serialize

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?

Upvotes: 0

Views: 433

Answers (3)

maxijb
maxijb

Reputation: 531

Or you could use in one line:

$("form:first").serialize();

Upvotes: 0

genesis
genesis

Reputation: 50976

First one selects all forms and serializes all form fields.

Second one selects form fields from FIRST form and serializes them

Upvotes: 2

Ilia Choly
Ilia Choly

Reputation: 18557

try this:

var theForm = $("form");
theForm.eq(0).serialize();

Upvotes: 2

Related Questions