admin管理员组文章数量:1326099
Let's say I have next construction
<table id="mainTable">
<tr>
<td>
<div class="parentDiv">
<input class="childInput"/>
<table>
<tbody>
<tr>
<td>
<span>I am here!</span>
<td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</table>
How can I get input
element from span
? Using jQuery or standart methods.
mainTable
has many rows so I can't use id
on input.
I can do it with:
$($(spanElement).parents(".parentDiv")[0]).children(".childInput")[0]
Do you know an easier way?
Let's say I have next construction
<table id="mainTable">
<tr>
<td>
<div class="parentDiv">
<input class="childInput"/>
<table>
<tbody>
<tr>
<td>
<span>I am here!</span>
<td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</table>
How can I get input
element from span
? Using jQuery or standart methods.
mainTable
has many rows so I can't use id
on input.
I can do it with:
$($(spanElement).parents(".parentDiv")[0]).children(".childInput")[0]
Do you know an easier way?
Share Improve this question edited Nov 30, 2012 at 15:02 DarkAjax 16.2k11 gold badges57 silver badges66 bronze badges asked Nov 30, 2012 at 15:00 IlyaIlya 29.7k19 gold badges119 silver badges161 bronze badges 1- 2 Read the jQuery docs for Traversing – I Hate Lazy Commented Nov 30, 2012 at 15:03
2 Answers
Reset to default 7$(spanElement).closest('.parentDiv').find('input');
$(spanElement).closest('.parentDiv').find('.childInput');
本文标签: javascriptGet nearest input element from same divStack Overflow
版权声明:本文标题:javascript - Get nearest input element from same div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742192891a2430542.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论