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 534603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:37:47+00:00 2026-05-13T09:37:47+00:00

I am willing to use the jquery treeview. I have categories and subcategories to

  • 0

I am willing to use the jquery treeview. I have categories and subcategories to choose for an item and I would like to display them in a treeview. I would like then to get the clicked value.

for the moment I am working on something of the kind of :

<ul id="treeview">
    <li>group1a
        <ul>
            <li>group11 </li>
        </ul>
    </li>
    <li>group2 </li>
    <li>group3 </li>
    <li>group4 </li>
    <li>group5 </li>
</ul>

and I tried this script, but the click function throw me an error.

<script type="text/javascript">
            $().ready(function () {
                $("#treeview").treeview();
            });

            $("#treeview").click(function (e) {
                e.target.addClass("selected");
            });

</script>

I am a very big beginner to this Jquery way of handling things, so I assume I am missing some important point somewhere… thanks for your help..

  • 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-05-13T09:37:48+00:00Added an answer on May 13, 2026 at 9:37 am

    The addClass is an jQuery method, while e.target is not a jQuery object. You need to enclose it in $():

    $("#treeview").click(function (e) {
        $(e.target).addClass("selected");
    });
    

    Your code won’t work anyways, as the click event is bound only to the #treeview element, and when that element fires, e.target will always be the #treeview element. What you’re looking for is probably something like this:

    $("#treeview li").click(function() {
        $(this).addClass("selected");
    });
    

    This binds the click function to all li elements, and when one of them is clicked, it adds the “selected” class to that element.

    Probably you want to also allow deselecting of objects, so you should use toggleClass instead of addClass. If you want to allow selecting of only one object, you could use this:

    $("#treeview li").click(function() {
        // Clear all selected states
        $('#treeview li').removeClass('selected');
        // Set current as selected
        $(this).addClass("selected");
    });
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm willing to use thumbnails into my website which is mainly like websites directory.
I'm willing to use data tag as below. <div data-color=#1337c></div> I use jquery to
I want to use a JQuery check all function in a form like this:
I am willing to build a wiki-based website that would have some other features,
First off I would like to say that I have done ample research on
Here is the sample I'm working with. I would like to not use any
I've set a CSS3 background gradient on an item, and I'd like to have
I am willing to use Google Analytics to track stats about usage of my
Can anyone find an example of a simple server/client thing? I'm willing to use
I am willing to develop a mobile application. I wish to have something working

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.