Ergec
Ergec

Reputation: 11824

jQuery - how to use multiple selectors one object and one id string

I need to serialize two form elements into one. But the problem is one has id #form1 but other is coming from elsewhere as an object let say variable objform

Serializing with two string IDs is easy

$("#form1, #form2").serialize();

How can I serialize one string and one object? Is there an elegant way doing it with object without assigning a dummy random id to the object form?

Upvotes: 0

Views: 48

Answers (2)

reyaner
reyaner

Reputation: 2819

try it like so:

//object2 into object1
$.extend(object1, object2);

Upvotes: 0

Tommi
Tommi

Reputation: 3247

You can use add method to add element to collection:

$("#form1").add(myObjectRef).serialize();

Upvotes: 1

Related Questions