I have a form object in jquery, and I'd like to select all inputs of this form.
Let's suppose my form object is called form. If the form has an id, I can just do
var id = form.attr('id');
var inputs = $('#' + id + ' input');
If not I can check this, and then manually add a temporary id, do the selection, and remove the id (or just leave it there). But this just looks too complicated, there must be an easier way, but I'm not able to find it.
Another possible way (which I'm not able to make work) would be something like
var inputs = $('input').filter(function() {
var parents = this.parents();
return ($.inArray(form, parents) != -1);
});
but this too seems complicated (and it doesn't work as stated).
By the way, from the performance point of view, which approach would be more convenient?