-2

I'm trying to create a submenu with js. but it doesnt work. I want to click the education(in a tag) so the ul(with class named sub) opens and shows the submenu.

here is the code:

<script language="javascript" type="text/javascript">
    function open()
    {
        var e = document.getElementById(sub);
        if(e.style.display == 'block'){
          e.style.display = 'none';
        }
        else{
          e.style.display = 'block';
        }
    }
</script>

<div id="submenu">
     <ul>
         <li class="headersub"><a href="" class="blue" onClick="open()">education</a>
              <ul  class="sub" style="display:none;">
                   <li>

                      <?php if(isset($_SESSION['user']))require('./module/adminmenu/adminmenu.php'); ?>
                     </li>
              </ul>
        </li>
Jaimin Soni
  • 1,061
  • 1
  • 13
  • 29
Rhan
  • 1
  • 3

1 Answers1

0

Is the page refreshing after you click on the link? If it is, then try:

function open(e) {
  e.preventDefault();
  // then your existing code here
}

This should solve the problem.

Abraar Arique Diganto
  • 1,215
  • 16
  • 24