简体   繁体   English

通过找到childs的data-id获得父元素的索引

[英]Get the index of the parent element, by finding the childs data-id

Is it possible by knowing the child's data-id to do a find().index() on the parent? 是否可以通过了解子代的数据ID对父代执行find()。index()? my code is as such: 我的代码是这样的:

<div class="owl-wrapper" style="width: 38640px; left: 0px; display: block;">
    <div class="owl-item" style="width: 280px;">
        <div class="itemchild" data-remid="67">
        </div>
    </div>
    <div class="owl-item" style="width: 280px;">
        <div class="itemchild" data-remid="135">
        </div>
    </div>
    <div class="owl-item" style="width: 280px;">
        <div class="itemchild" data-remid="136">
        </div>
    </div>
</div>

i want to get the index of the itemchild element, that contains a chile with a specific data-remid 我想获取itemchild元素的索引,其中包含具有特定数据需求的智利

something like: .find("[data-remid='" + ID + "'"]).parent().index(); 类似于: .find("[data-remid='" + ID + "'"]).parent().index();

You haven't handled the quotes correctly while making selector. 选择器时,您没有正确处理引号。 Use: 采用:

$("[data-remid=" + ID + "]").parent().index();

Working Demo 工作演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM