jQuery 兄弟姐妹的孩子的jQuery选择器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3563594/
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
jQuery selector for child of sibling?
提问by Walker
I'm trying to get a jQuery selector for the child of a sibling (multiple sections on the page so need to just reach the sibling's child (rather thna being able to use a general selector).
我正在尝试为兄弟姐妹的孩子获取 jQuery 选择器(页面上的多个部分,因此只需要到达兄弟姐妹的孩子(而不是能够使用通用选择器)。
HTML:
HTML:
<div class="tour-section">
<div class="screenshots left">
<div class="tab tab1"></div>
<div class="tab tab2"></div>
<div class="tab tab3"></div>
<div class="tab tab4"></div>
</div>
<div class="talking-point section1">
<h2 class="primary-color-text">Create your listing</h2>
<p class="subheader">Create your job listing by adding a few simple details</p>
</div>
</div>
JS:
JS:
$(".talking-point.section1").mouseenter(function() {
$(this).siblings(".screenshots").children("tab").hide();
$(".screenshots .tab1").show();
$(this).siblings(".screenshots").css("background-position","0 0");
});
采纳答案by jAndy
Logically it should work. You're missing a dot .
for the .children()
Jquery selector.
从逻辑上讲它应该工作。你缺少点.
的.children()
jQuery选择。
.children(".tab")
回答by warvariuc
Using find
instead of children
worked for me:
使用find
而不是children
为我工作:
$(this).siblings(".screenshots").find("tab")
回答by kennytm
Do you mean children(".tab")
?
你的意思是children(".tab")
?