Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7777409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:08:06+00:00 2026-06-01T18:08:06+00:00

I have some hierarchical data I am manipulating with JQuery, and I am trying

  • 0

I have some hierarchical data I am manipulating with JQuery, and I am trying to add some type of visual indication about which elements in my tree are selected. Here is a sample of the html I am generating (which we are manipulating):

<li>
    <input class="selectedcheck" checked disabled type="checkbox" name="ign-130">
    <input class="millermultiselect" type="checkbox" name="chk-130">
    <a href="#" data-parent="6" data-nodename="Egypt" data-self="130">Egypt</a>
    <ul>
          <li>
                <input class="selectedcheck" checked disabled type="checkbox" name="ign-131">
                <input class="millermultiselect" type="checkbox" name="chk-131">
                <a href="#" data-parent="130" data-nodename="Cairo" data-self="131">Cairo</a>
          </li>
    </ul>
</li>

All of this resides within a div#miller. The first check box (.selectedcheck), is used only to show that a region is selected (it starts out hidden, and is shown when the parent region is selected, so if you clicked the .millermultiselect in Egypt, the .selectedcheck in Cairo would become visible replacing Cairo’s .millermultiselect). What I would like to do is also add a class to any li which contains (as a direct child) a checked check box. I am attempting to accomplish this with the following JQuery code:

$("#miller li:has(input:checkbox:checked:visible)").addClass('chosen');

The problem that I am having is that since all of the regions are composed of nested ul’s, checking a check box in any region also adds .chosen to any li higher in the tree… so clicking the check box for Cairo adds the .chosen class to Egypt and Africa.

Anyone have an idea how I would go about only capturing li’s that have a visible, checked check box as a direct child?

Here is my whole js file just in case it provides insight:

$(document).ready(function() {
    $(".selectedcheck").hide();
    showSelected = function(){
        $("#miller li").removeClass("chosen");
        $("#miller li:has(input:checkbox:checked:visible)").addClass('chosen');
    };
    $("#miller a").click(function(event) {
        event.preventDefault();
        $("#miller li").removeClass("selected");
        $(this).parent().addClass("selected");
        data = $(this).data();
        $("#addChild").attr("href", "addChild.php?parentid=" + data.self).html("Add item under " + data.nodename);
        $("#addSibling").attr("href", "addChild.php?parentid=" + data.parent).html("Add item next to " + data.nodename);
        $("#editRegion").attr("href", "editRegion.php?id=" + data.self).html("Edit " + data.nodename);
        $("#deleteRegion").attr("href", "deleteRegion.php?id=" + data.self).html("Delete " + data.nodename);
        $("#addResort").attr("href", "addResort.php?regionid=" + data.self).html("Add resort to " + data.nodename);
        $("#miller ul ul").hide();
        $(this).parents("#miller ul").show();
        $(this).siblings("#miller ul").show();
        showSelected();
    });
    $("#miller .millermultiselect").click(function(event) {
        $("#miller li").removeClass("selected");
        $(this).parent().addClass("selected");
        $("#miller ul ul").hide();
        $(this).parents("#miller ul").show();
        if($(this).is(':checked')) {
            $(this).parent().find(".millermultiselect").not(this).hide();
            $(this).parent().find(".millermultiselect").not(this).removeAttr("checked");
            $(this).parent().find(".selectedcheck").show();
        } else {
            $(this).parent().find(".millermultiselect").not(this).show();
            $(this).parent().find(".selectedcheck").hide();
        }
        $(this).siblings(".selectedcheck").hide();
        $(this).siblings("#miller ul").show();
        showSelected();
    });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:08:07+00:00Added an answer on June 1, 2026 at 6:08 pm

    You can use the direct descendant selector and then get it’s parent:

    $("#miller li > input:checkbox:checked:visible").parent().addClass("chosen");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some hierarchical data - each entry has an id and a (nullable)
I have some hierarchical data that I need display as a table, can I
I have some hierarchical data that I need to display in a series of
I'm working on a project where I have some hierarchical data that I want
I have hierarchical data stored in the datastore using a model which looks like
I have some hierarchical data in a Rails 3 applications. It allows the user
I need to create an algorithm to layout some hierarchical data but have never
I have data database containing some rather large strings, each of which holds a
Say that have the following CTE that returns the level of some tree data
Let's assume we have a method handling operations in a tree hierarchical data structure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.