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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:40:09  来源:igfitidea点击:

jQuery selector for child of sibling?

jqueryjquery-selectors

提问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 findinstead of childrenworked for me:

使用find而不是children为我工作:

$(this).siblings(".screenshots").find("tab")

回答by kennytm

Do you mean children(".tab")?

你的意思是children(".tab")