i have this html
<ul>
<li><form action="#" name="formName"></li>
<li><input type="text" name="someName" /></li>
<li><input type="text" name="someOtherName" /></li>
<li><input type="submit" name="submitButton" value="send"></li>
<li></form></li>
</ul>
How can i select the form that the input[name="submitButton"]
is part of ?
(when i click on the submit button i want to select the form and append some fields in it)
I would suggest using closest
, which selects the closest matching parent element:
$('input[name="submitButton"]').closest("form");
Instead of filtering by the name, I would do this:
$('input[type=submit]').closest("form");