兄弟姐妹的jQuery选择器?

Wal*_*ker 23 jquery jquery-selectors

我正在尝试为兄弟的孩子提供一个jQuery选择器(页面上有多个部分,所以需要到达兄弟的孩子(而不是能够使用常规选择器).

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>
Run Code Online (Sandbox Code Playgroud)

JS:

$(".talking-point.section1").mouseenter(function() {
            $(this).siblings(".screenshots").children("tab").hide();
            $(".screenshots .tab1").show();
            $(this).siblings(".screenshots").css("background-position","0 0");
        }); 
Run Code Online (Sandbox Code Playgroud)

jAn*_*ndy 17

逻辑上它应该工作.你缺少点..children()jQuery选择.

.children(".tab")
Run Code Online (Sandbox Code Playgroud)

  • 不幸的是,这不是:( (2认同)
  • 请注意:“.children()”搜索直接子项,而不是子项的子项(嵌套)。因此,如果您需要查找可能(不)嵌套在子级中的子级,请使用“.find()” (2认同)

war*_*iuc 7

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

$(this).siblings(".screenshots").find("tab")
Run Code Online (Sandbox Code Playgroud)