How to loop through all elements of a form jQuery
Solution 1:
From the jQuery :input selector page:
Because :input is a jQuery extension and not part of the CSS specification, queries using :input cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. To achieve the best performance when using :input to select elements, first select the elements using a pure CSS selector, then use .filter(":input").
This is the best choice.
$('#new_user_form *').filter(':input').each(function(){
//your code here
});
Solution 2:
pure JavaScript is not that difficult:
for(var i=0; i < form.elements.length; i++){
var e = form.elements[i];
console.log(e.name+"="+e.value);
}
Note: because form.elements is a object for-in loop does not work as expected.
Answer found here (by Chris Pietschmann), documented here (W3S).
Solution 3:
$('#new_user_form').find('input').each(function(){
//your code here
});