# Directory Tree Issue

**URL:** https://forum.kirupa.com/t/directory-tree-issue/286513
**Category:** web dev
**Created:** [April 16, 2009, 2:54pm UTC](https://forum.kirupa.com/t/directory-tree-issue/286513 "2009-04-16T14:54:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![redelite](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@redelite](https://forum.kirupa.com/u/redelite)
#### Post date: [April 16, 2009, 2:54pm UTC](https://forum.kirupa.com/t/directory-tree-issue/286513/1 "2009-04-16T14:54:22Z")

</div>

```auto

<ul id="topLevelDirectoryFiles">
  <li class="toggle" id="applications">applications
    <ul id="applications-child" class="open">
      <li class="toggle" id="applications-lib">lib</li>
      <li class="toggle" id="applications-images">images</li>
      <li class="toggle" id="applications-css">css</li>
      <li class="toggle" id="applications-views">views</li>
    </ul>
  </li>
</ul>

```

```auto

$('li').click(function() {
  if ($('li > ul').length) {
    alert($(this).attr('id'));
  } else {
    getDirectoryContents($(this).attr('id'));
  }
});

```

Okay, so the JQuery is supposed to work like this:

[LIST=1]  
[_]Check if an \<li\> is clicked  
[_]If the \<li\> has a \<ul\> inside of it already  
[LIST=1]  
[\*]Alert the \<li\>'s _ID_… (which SHOULD give me applications-lib, if you clicked on lib)  
[/LIST]

[\*]Otherwise get the list of directories based on the element ID  
[/LIST]  
For some reason when I click a 2nd tier \<li\> it gives me the 1st tier ID every time. Any thoughts why?
