I have a form that has no id, no class whatsoever. I need to get all the inputs that are inside it, I have a script but it will get all inputs no matter if they are inside my form or not.
Of course I could add classes, id’s to my forms but is there any way of doing what I want without adding identifiers to my form?
It is only logical that in my case it will iterate trough every input on my page, but how can I make sure it will only iterate trough every input on current form?
$('form').submit(function(e){
e.preventDefault();
$('input, textarea').each(function(){
alert('a'); // Alerts on every input, not just inside this form...
});
});
Fiddle: http://jsfiddle.net/dsN43/
You can pass
thisas context (second parameter) to jQuery function to search only inside current element.