I would like to get the same affect as jQuery.serialize() but I would like to return only the child elments of a given div.
sample result:
single=Single2&multiple=Multiple&radio=radio1
Source: Tips4all
Cisco Certified Network Associate Exam,640-802 CCNA All Answers ~100/100. Daily update
I would like to get the same affect as jQuery.serialize() but I would like to return only the child elments of a given div.
sample result:
single=Single2&multiple=Multiple&radio=radio1
No problem. Just use the following. This will behave exactly like serializing a form but using a div's content instead.
ReplyDelete$('#divId *').serialize();
Check http://jsbin.com/azodo for a demonstration (http://jsbin.com/azodo/edit for the code)
You can improve the speed of your code if you restrict the items jQuery will look at.
ReplyDeleteUse the selector :input instead of * to achieve it.
$('#divId :input').serialize()
This will make your code faster because the list of items is shorter.
Try also this:
ReplyDelete$('#divId').find('input').serialize()
jitter's solution helped me from a more generic viewpoint. Clicking a link, finding it's parent div and then serializing:
ReplyDelete//$(this) is a "click"able item within the div
var divid = $(this).closest('div').attr('id);
var data = $('#'+ divid+ ' *').serialize();