Hello. For some reason, links in the tree menu do not work. Only subcategory links work. That is, in my case, only the category "Helicopters" has subcategories. Categories get from the database mysql. The menu is made on jQuery (the menu was pulled from the Internet, I don’t think in js) Look, please, maybe an error somewhere in the js file? I do not suggest anything else. Disabled the CSS file, the problem remained.

enter image description here

$(document).ready(function () { $('.sub > a').click(function(){ if ($(this).attr('class') != 'active'){ $('.sub ul').slideUp(); $(this).next().slideToggle(); } return false; }); $('.mini-menu > ul > li > a').click(function(){ $('.mini-menu > ul > li > a, .sub a').removeClass('active'); $(this).addClass('active'); }), $('.sub ul li a').click(function(){ $('.sub ul li a').removeClass('active'); $(this).addClass('active'); }); $('.slider_slick_items').slick({ prevArrow: '<i id="prev_arrow_slider" class="fa fa-angle-left"></i>', nextArrow: '<i id="next_arrow_slider" class="fa fa-angle-right"></i>' }); }); 
 php код (на всякий случай) $tree = []; foreach ($data as $elem) { $tree[(int) $elem['parent_id']][] = $elem; } function treePrint($tree, $pid=0) { if (empty($tree[$pid])) { return; } echo '<ul>'; foreach ($tree[$pid] as $k => $row) { if ($row['parent_id'] > '0') { $class = 'down_item'; } else { $class = 'sub'; } echo "<li class=\"$class\"><a href=\"?itemCard=$row[id]\">$row[category]</a>"; if (isset($tree[$row['id']])) treePrint($tree, $row['id']); echo '</li>'; } echo '</ul>'; } ?> <div class="mini-menu"> <?php treePrint($tree); ?> </div> 

    1 answer 1

    Because the handler returns false, so it does not click. They work on opening a submenu.

      $('.sub > a').click(function(){ if ($(this).attr('class') != 'active'){ $('.sub ul').slideUp(); $(this).next().slideToggle(); } return false; }); 

    It is necessary to remove the class sub, where you need to follow the link, and not the submenu expansion. Or remove the return false; in the handler.

    • I need to follow the link everywhere, where there are no subcategories. That is, I already create a condition at the php level and if there is a submenu, then leave the "sub" class, and where not, then another class? Or in the js file to edit something? - Roman
    • Already at the level of php to create a condition and if there is a submenu, then leave the class "sub", and where not, then another class. Yes that's right. - Maxim Stepanov