简体   繁体   中英

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? 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

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

You haven't handled the quotes correctly while making selector. Use:

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

Working Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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