title: My jQuery hide/view function works but does not if executed through another script
body: <p>I've made a function to hide/view my category menu: </p>
  
  <p>The script:
           </p>
  
  <pre><code>      function toggle(id) {
  
           var e = document.getElementById(id);
           if(e.style.display == 'block')
              e.style.display = 'none';
           else
              e.style.display = 'block';
        }
  
        &lt;/script&gt;
  </code></pre>
  
  <p>I use it on a p tag like this:   </p>
  
  <pre><code>     &lt;p onclick="toggle('foos');";&gt;Category&lt;/p&gt;
  </code></pre>
  
  <p>The above works perfectly. When I click on "Category" it shows or hide my div. </p>
  
  <p>However I then made another menu as a list. I want to execute my "toggle" function when you click on one of the "li" from my list. </p>
  
  <p>I've tried to do that with this:</p>
  
  <pre><code>    $(".uldropdown").on('click','li',function (){
  
      $("#displaytwo .menu p").click();
  
      });
  </code></pre>
  
  <p>But when I click on one of the "li" it shows my category menu only for a split second and then it immediately disappears. </p>
  
  <p>So it almost works, but for some reason the div disappears immediately right after the click. I hope someone can tell me whats wrong. Thank you</p>
  
  <p>Edit:
  <strong>This is my list menu:</strong></p>
  
  <pre><code>     echo '&lt;div id="foo"&gt;';
       echo '&lt;ul id="uldropdown" class="uldropdown"&gt;
  
       &lt;ul&gt;';
  
  
     while($row = mysqli_fetch_array($results)) {
      echo '&lt;li  class="lidropdown"&gt;'.$row['name'].'&lt;/li&gt;';
  
      }
      echo '&lt;/ul&gt;
     &lt;/ul&gt;&lt;/div&gt;';
  </code></pre>
  
  <p><strong>My category menu:</strong> </p>
  
  <pre><code>      &lt;div class="hejsa" &gt;
        &lt;p onclick="toggle('foos');";&gt;Category&lt;/p&gt;
  
        &lt;?php
          echo '
          &lt;div id="foos"&gt;';
  
           echo '&lt;ul id="catdropdown" class="catdropdown"&gt;
  
                &lt;ul&gt;';
  
          while($row = mysqli_fetch_array($resultcats)) {
              echo '&lt;li  class="catdropdown" onclick="location.reload()"; "&gt;'.$row['category'].'&lt;/li&gt;';
  
          }
          echo '&lt;/ul&gt;
          &lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;';
  </code></pre>
  
  <p>I did not add some of the SQL parts, just to keep it as simple as possible. </p>