jquery transverse to get children within a child -
i having trouble on figuring out best way transverse form origin , find inputs within child.
heres form:
<form class="ajax-submit-createuser clr mrg-btm-med" method="post" action="./createuser.php">   <table class="fixed">     <tr>       <td><p>enter username</p></td>       <td><input name="formname" type="text" placeholder="username" autocomplete="off" required /></td>     </tr>     <tr>       <td><p>enter email address</p></td>       <td><input name="formemail" type="email" placeholder="email address" autocomplete="off" required /></td>     </tr>     <tr>       <td><p>enter password</p></td>       <td><input name="formpass" type="password" placeholder="enter password" autocomplete="off" required /></td>     </tr>     <tr>       <td></td>       <td><button class="trg-createuser btn btn-default"><i class="fa fa-fw fa-plus"></i> create</button></td>     </tr>   </table> </form> i have tried:
var formname = $(this).closest("input[name=formname]").val(); and
var formname = $(this).siblings().siblings("input[name=formname]").val(); var formname = $(this).siblings().siblings().siblings("input[name=formname]").val(); but don't seem work, best way of transversing this?
you can use find(). assuming this refers form element, try this:
var formname = $(this).find("input[name=formname]").val(); for reference, closest() find nearest parent element matching given selector. siblings() used find elements same parent current, not go up/down dom @ all.
Comments
Post a Comment