I wish to iterate through a form, adding each element to an area. The problem is that some of these elements are select, input, and textboxes. I know that I can use :input to solve the problem here (though, I don’t really need to). The issue is that I’m having trouble determining how I could see whether or not the element is a textarea, input, select, etc. I need to do this properly because, as far as I know, jQuery("input#someinput").val() works great for inputs, but for a textarea I may need jQuery("textarea#sometexarea").text(). I’m not sure if this exists…
Anyway, here’s my function so far:
function getAllFormElements(id) {
var elements = new Array();
jQuery(id).children().map(function(){
for (var index = 0; index < children.length; index++) {
elements[i] = jQuery(children[i]).val();
}
})
return elements;
}
val() works equally well with
<input>,<select>and<textarea>elements.If you still want to determine the actual type of elements matched by the
:inputselector, you can use is() with element selectors: