Jump to content

JavaScript & Php-Mysql accordion menu overlap


Recommended Posts

Hi everyone,

I have problem with my accordion menu. Instead of sliding down, content from menu overlap each other...Cut me a little slack because i am new to javascript.

This is code for menu.

<?php include("script/dblib.php");
header("Content-Type: text/html; charset=UTF-8");
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="script/script.js"></script>
#accordion {
list-style: none;
padding: 0 0 0 0;
width: 230px;
#accordion li{
display: block;
background-repeat:repeat-x repeat-y;
font-weight: bold;
padding-left: 5px;
cursor: pointer;

list-style: circle;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
#accordion ul {
list-style: none;
padding: 0 0 0 0;
display: none;
#accordion li:hover{
#accordion ul li{
text-align: center;
font-size: 12px;
font-weight: normal;
cursor: auto;
padding: 0 0 0 7px;
#accordion ul li:hover {
#accordion a {

text-decoration: none;


// Select all entries from the menu table
$result=mysql_query("SELECT * FROM parents ORDER BY id_roditelja");

// Create a multidimensional array to conatin a list of items and parents

$menu = array(
   'items' => array(),
   'parents' => array()
// Builds the array lists with data from the menu table
while ($items = mysql_fetch_assoc($result))
   // Creates entry into items array with current menu item id ie. $menu['items'][1]
   $menu['items'][$items['id_roditelja']] = $items;

   // Creates entry into parents array. Parents array contains a list of all items with children
   $menu['parents'][$items['parent_id']][] = $items['id_roditelja'];
// Menu builder function, parentId 0 is the root
function buildMenu($parent, $menu)
  $html = "";
  if (isset($menu['parents'][$parent]))
     $html .= "
     <ul id='accordion'>\n";
      foreach ($menu['parents'][$parent] as $itemId)
            $html .= "<li>\n  <a >".$menu['items'][$itemId]['naziv']."</a>\n</li> \n";
            $html .= "
            <li>\n  <a >".$menu['items'][$itemId]['naziv']."</a> \n";
            $html .= buildMenu($itemId, $menu);
            $html .= "</li> \n";
      $html .= "</ul> \n";
  return $html;

echo buildMenu(0, $menu);





javascript part:


 $('#accordion > li ul')

 $('#accordion > li, #accordion > li > ul > li').click(function(){
   var selfClick = $(this).find('ul:first').is(':visible');
   if(!selfClick) {
       .find('> li ul:visible')

     .stop(true, true)


This is image of what is happening


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.