0

I dont know how to approach this. I would like to be able to do the following: I have a icon for a folder that links to another page. When the user clicks on the icon, instead of going to the page, a subfolder(s) appears below the folder icon and when the user clicks on one of these folders, then it directs the user to the page.

Below is what I did orignally:

<h4>
  <a href="CalMediConnect_DMgmt.cfm">
    <img src="images/folder-documents-icon32.jpg" alt="Custodial" class="float-left">
    &nbsp;Disease Management
  </a>
</h4> 
<br /><br />

UPDATE

I have tried the following and it appears to not be working:

The following is the script:

var tree = document.querySelectorAll('ul.tree a:not(:last-child)');
for(var i = 0; i < tree.length; i++) {
  tree[i].addEventListener('click', function(e) {
    var parent = e.target.parentElement;
    var classList = parent.classList;
    if(classList.contains("open")) {
      classList.remove('open');
      var opensubs = parent.querySelectorAll(':scope .open');
      for(var i = 0; i < opensubs.length; i++) {
        opensubs[i].classList.remove('open');
      }
    } else {
      classList.add('open');
    }
  });
}

The following is the CSS:

ul.tree li {
  list-style-type: none;
  position: relative;
}

ul.tree li ul {
  display: none;
}

ul.tree li.open > ul {
  display: block;
}

ul.tree li a {
  color: #4284B0;
  text-decoration: none;
}

ul.tree li a:before {
  height: 1em;
  padding: .1em;
  font-size: .8em;
  display: block;
  position: absolute;
  left: -1.3em;
  top: .2em;
}
.margin-left {
  margin-left: -15px;
}

And the HTML:

<ul class="tree margin-left">
  <li>
    <h4>
      <a href="#">
        <img src="images/folder-documents-icon32.jpg" alt="Custodial" class="float-left">
        &nbsp;Disease Management
      </a>
    </h4>
    <ul>
      <li>
        <h5>
          <a href="CalMediConnect_DMgmt.cfm">
            <img src="images/folder-documents-icon32.jpg" alt="Custodial" class="float-left">
            &nbsp;Disease Management
          </a>
        </h5>
      </li>
    </ul>
  </li> 
</ul>

Any help would be appreciated.

Nhan
  • 3,595
  • 6
  • 30
  • 38
Roberto Flores
  • 775
  • 2
  • 12
  • 46

1 Answers1

1

Here is a very basic example built with jQuery...

https://jsfiddle.net/kennethcss/8b4e6o42/

$('.folder').on('click', function(e) {
  var folder = $(this).find('.sub-folder');

  if (e.target !== this) return;

  if(folder.hasClass('hidden')) {
    folder.removeClass('hidden');
  } else {
    folder.addClass('hidden');
  }
});
.folder {
  cursor: pointer;
}

.hidden {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

<ul class="container">
  <li class="folder">Primary
    <ul class="sub-folder hidden">
      <li>Secondary</li>
      <li>Secondary</li>
      <li>Secondary</li>
    </ul>
  </li>
  <li class="folder">Primary
    <ul class="sub-folder hidden">
      <li>Secondary</li>
      <li>Secondary</li>
      <li>Secondary</li>
    </ul>
  </li>
  <li class="folder">Primary
    <ul class="sub-folder hidden">
      <li>Secondary</li>
      <li>Secondary</li>
      <li>Secondary</li>
    </ul>
  </li>
</ul>

Of course, you can style however you'd like; this example merely demonstrates how you might structure your HTML, CSS and JS to create a simple, folder like structure.

Gist

https://gist.github.com/kennethcss/8db1dc3326917c77846e84d263beb67d

Kenneth Stoddard
  • 1,409
  • 11
  • 13