user3852972
user3852972

Reputation: 35

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');

            // 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);
        });

    });

Upvotes: 0

Views: 83

Answers (1)

joews
joews

Reputation: 30330

You're missing a jQuery selection:

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

e.target.parentElement is a DOM element object, not a jQuery selection.

Upvotes: 2

Related Questions