简体   繁体   English

jQuery为选定对象获取子级

[英]jQuery get children for selected object

I have a selected object that was clicked. 我有一个单击的选定对象。 When this happens, i would like to retrieve the object and then find the children with a specific class value so i can disable them. 发生这种情况时,我想检索对象,然后找到具有特定类值的子项,以便可以禁用它们。

I am able to get the object but when i access the children i always get "undefined" even though i can see the children. 我可以获取对象,但是当我访问孩子时,即使我看到孩子也总是得到“未定义”。 I browsed the object and i can see the class attributes values i am looking for. 我浏览了该对象,然后可以看到我要查找的类属性值。

Can somebody please tell me if i am referencing this correctly? 有人可以告诉我是否正确引用了吗? Below is my code, The specific line with the issue is, 以下是我的代码,与该问题有关的具体内容是:

var kids = clicked_obj.children('.ui-selected'); var kids = clicked_obj.children('。ui-selected');

            // manually trigger the "select" of clicked elements
        $(".page").click(function (e) {
            console.log(e);
            //var selected_divs = $(".page").find("div[class*='ui-selected']");
            var selected_divs = $(".page").find(".existingFieldItem.ui-selected");

            selected_divs.each(function () {
                if (e.ctrlKey == true) {
                    var clicked_obj = e.target.parentElement;
                    var kids = clicked_obj.children('.ui-selected');

                    console.log("Ctrl clicked");
                    console.log($(this).attr("id"));

                    kids.each(function () {
                        $(this).removeClass("ui-selected");
                    });


                    // if command key is pressed don't deselect existing elements
                    $(this).removeClass("ui-selected");
                    $(this).addClass("ui-selecting");


                }
                else {
                    if ($(this).hasClass("ui-selected")) {
                        // remove selected class from element if already selected
                        $(this).removeClass("ui-selected");
                    }
                    else {
                        // add selecting class if not
                        $(this).addClass("ui-selecting");
                    }
                }
            });

            $(".page").data("ui-selectable")._mouseStop(null);
        });

    });

You're missing a jQuery selection: 您缺少jQuery选择:

var clicked_obj = $(e.target.parentElement);

e.target.parentElement is a DOM element object, not a jQuery selection. e.target.parentElement是DOM元素对象,而不是jQuery选择。

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

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