jQuery 如何使用jQuery在指定元素之前找到div?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1345354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find the div before a specified element with jQuery?
提问by omg
<td>
<div class="resumehint"></div>
<input type="file" id="resume" />
</td>
How to get the div before "#resume" with jQuery?
如何使用jQuery在“#resume”之前获取div?
That is ".resumehint"
那就是“.resumehint”
回答by Jason
$(this).prev("div")
or
或者
$(this).prev()
or
或者
$(this).prev(".resumehint")
you can replace $(this)
with $('#resume')
if you are outside a function.
如果您在函数之外$(this)
,$('#resume')
则可以替换为。
回答by Ashish Yadav
for multiple elements:
对于多个元素:
$('#resume').prevAll()
回答by CMS
Use the Traversing/prevfunction:
使用Traversing/prev功能:
$('#resume').prev('div');
And if you know the CSS class of the div to be more specific:
如果您知道 div 的 CSS 类更具体:
$('#resume').prev('div.resumehint');
回答by rahul
$("#resume").prev();