【问题标题】:Jquery find or children with all occurrences of elements with a class , and skipping a middle level and restricted to their levelJquery查找所有出现的具有类的元素的子级,并跳过中间级别并限制在他们的级别
【发布时间】:2019-03-24 08:36:52
【问题描述】:

我需要帮助获得正确的选择器和限制,以便在给定 HTML 的下方位的特定级别检索子元素。

我有第一个元素,即顶部的 li。

我需要在子 ul 下获取它的子级,它们具有类“subtree-checkbox”。 为了清楚起见,附上一张图片。 非常感谢。

<li class="green checked" style="color: yellow; border: 2px solid yellow;">
<span class="accordion-heading" data-toggle="collapse" aria-expanded="true" data-target="#Smenu_0_1__1">
    <span id="sp_SM_0_1" class="checkbox subtree-checkbox styled red"><input name="SM_0_1" class="subtree-checkbox styled red" id="SM_0_1" type="checkbox" iid="1" value="false" style="display: none;"></span>
    Users
</span>
<ul class="nav nav-list collapse in" id="Smenu_0_1__1" style="padding-left: 60px;" aria-expanded="true">
    <li>
        <span class="accordion-heading" data-toggle="collapse" data-target="#Smenu_0_1__10" aria-expanded="true">
            <span id="sp_SM_0_1_1" class="checkbox subtree-checkbox styled grey checked" style="color: yellow; border: 2px solid yellow;"><input name="SM_0_1_1" class="subtree-checkbox styled red" id="SM_0_1_1" type="checkbox" iid="2" value="false" style="display: none;"></span>
            new subby tst3
        </span>
        <ul class="nav nav-list collapse in" id="Smenu_0_1__10" aria-expanded="true" style="padding-left: 20px;">
            <li>
            </li>

            <li>
            </li>

            <li>
            </li>

            <li>
            </li>
        </ul>
    </li>
</ul>

我试过了,但显然失败了。

    var kiddieEls = $(SpanParent).children("input[type=checkbox]");

还有这个

    var kiddieEls =$(SpanParent).children('ul').find("subtree-checkbox:first-child");

如何获得该级别的一个或所有子元素?

【问题讨论】:

    标签: html find jquery-selectors children


    【解决方案1】:

    这是我想出的,可能不是最好的方法,但它确实有效。

    我在“LiParent”中有父李,这是我的起点。

    //  finds the ULs under this li element
    var childUL = $(LiParent).children('ul .nav-list');
    
    // gets the first level of children (li's)
    var FirstLi = $(childUL).children().first();
    
    //use that first child to find the required spans
    var ChkBoxSpanS_ToAccumulate = $(SpanAccordionchild).children('span').first()
    

    【讨论】:

      猜你喜欢
      • 2016-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      • 2017-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多