If the navigation menu contains sub-menus, it should slide to the left

I am currently working on developing a navigation menu with four levels of depth. The menu displays three levels at a time, and when the user reaches the fourth level, the first level should move to the left to make room for the second, third, and fourth levels.

However, I'm encountering an issue where clicking on a menu item in the third level (without children) also causes the menu to move left.

For example: Clicking on Menu-item1 > Menu-item1.2 > Menu-item1.2.2 > Menu-item1.2.2.1 moves the menu left even though Menu-item1.2.2.1 has no children.

How can I adjust my code so that the menu only moves left if it has child sub-menus?

Below is the code snippet:

... (code snippet goes here)

Check out the Codepen link here

Answer №1

Here is a suggestion to try out:

    $('.sub-sub-col > ul > li').click(function() {
     if(!$(this).find('.sub-sub-sub-col').length){
      return false;
     }
  var checks = $(this).data('checks'); //add your code here
});

Alternatively:

 if(!$(this).children('.sub-sub-sub-col').length){
  return false;
 }

================================================

//   if click on sub-col
  $('.sub-col > ul > li').on('click', function(){
      if (!$(this).hasClass('active')) {
        $('.dropdown').animate({
             'left' : '10px'
        })  
      }
  });

   $('.sub-sub-col > ul > li').click(function() {
  // var clicks = $(this).data('clicks');
      if (!$(this).hasClass('active')) {
        $('.dropdown').animate({
             'left' : '10px'
        })   
      }
      else {
        $('.dropdown').animate({
             'left' : '-510px'
        })
      }
  // $(this).data("clicks", !clicks);
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with rendering in sandbox environment versus localhost

Here's a dilemma I'm facing - I have some HTML code on my localhost that looks like this: <div> <p>Go to: <a href="www.foobar.com">here</a></p> </div> On localhost, the output is "Go to: here" with 'he ...

Counting the number of times a form is submitted using a submit button and storing the data

After researching for a few hours, I've gathered information on different techniques for storing data related to a submit button counter in a text file. <form action="/enquiry.php" method="post" name="form"> <label>Name *</label> &l ...

Trouble with jQuery autocomplete function in Firefox

I've implemented multiple jQuery autocomplete searches similar to this one. While they function properly in Safari, Chrome, and Opera, I'm encountering issues with Firefox. Could it be due to deprecated code usage? The jQuery UI example seems si ...

Adjusting image dimensions dynamically using JavaScript based on screen size

My bootstrap setup seems to be causing issues when using the @media (min-height: 1000px) rule as the image class does not respond as expected. I am looking to implement a JavaScript solution that will automatically resize images once the screen height exc ...

When the Chrome Dev Tools are activated, the responsive website malfunctions

As I work on designing a responsive website, I've encountered an issue with media queries. When I set the breakpoint to min-width: 320px in Chrome dev tools, all of my CSS styles disappear. The same problem occurs when I zoom the window size to 150%, ...

Clickable Href in jquery autocomplete

These are the codes I am currently using: <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.1 ...

Angular is unable to eliminate the focus outline from a custom checkbox created with Boostrap

Have you noticed that Angular doesn't blur out the clicked element for some strange reason? Well, I came up with a little 'fix' for it: *:focus { outline: none !important; } It's not a perfect solution because ideally every element sh ...

The use of @font-face in CSS seems to be malfunctioning

I am having trouble changing the font in my CSS to what I want it to be. body{ background-color:#a8a7a7; color:#C50909; font-family: main, Calibri; text-align:center; } @font-face{ font-family: main; src: url('fonts/RegencieLight.ttf'); } ...

"Introducing a smooth animation effect to shift text alignment to the center

I'm currently using the code below, but I am not satisfied with the margin adjustment achieved by text-align:center;. Is there a way to smoothly transition the text alignment to center similar to how it is done in the following snippet of code? if ($ ...

Identifying Even Selections in jQuery Even with the First Option

I am currently working with a select set-up that looks like this: <select> <option value="1">one</option> <option value="2">two</option> </select> My goal is to be able to detect when a choice is made, regardless of wh ...

Sort table rows by checkbox value in javascript

Is there a way to use javascript or JQuery to group the rows in this table by Office or Age based on the checkbox option selected? For example, if the Office checkbox is checked, the table rows should be grouped by Office. If the Age checkbox is checked, ...

What could be the reason for the malfunctioning of the "subscribe" button?

Whenever the subscribe button is clicked, it should send an email to the "subscriptions" section of the database. Unfortunately, when I click the button, nothing seems to happen. My understanding of this is very limited and I can't seem to troubleshoo ...

The pair of divs with distinct backgrounds

Looking to customize the navigation on my website by creating a separate background for the list links menu and making sure the left part of the navigation with the logo has its own distinct background that extends until the next div. I've experimente ...

Navigating to a particular div using a click event

I am trying to achieve a scrolling effect on my webpage by clicking a button that will target a specific div with the class "second". Currently, I have implemented this functionality using jQuery but I am curious about how to accomplish the same task using ...

Creating a functionality in jQuery that allows users to dynamically add a new row by clicking a button

Hello all, I am currently facing an issue with my code where I need to call a text box (or a set of divs with input fields) multiple times by clicking a button (with the id 'add_row'). The current code works fine for the first time, but not for ...

What steps should I take to repair my jQuery button slider?

I am facing a challenge with creating a carousel of three images in HTML using jQuery. When the user clicks on the "Next" or "Previous" buttons, I want to scroll through the images one by one. However, I am struggling to hide the other images when one is d ...

The CSS outline has a soft, rounded appearance rather than a sharp

Is there a way to prevent my outline from having rounded corners as it expands during the animation? Note: The issue seems to be present on Linux and MS Edge, but works fine on Mozilla Firefox. Any solutions for MS Edge users? Check out the code on Codep ...

Internet Explorer poses challenges for the jQuery Validate plugin's functionality

My form is utilizing jQuery validate and functions flawlessly in all browsers except for IE. I have tried various solutions provided in other posts but none have worked so far. Removing trailing commas was suggested, but that did not fix the issue. Any ass ...

Retrieving information from database with the help of PHP and AJAX

I am having trouble printing data from a PHP and Ajax request that is initially encoded into JSON. Instead of displaying the data properly on the screen, it is showing elements from four rows all in a single line with commas separating them. $(document ...

Exploring the capabilities of the jQuery `val()` function alongside the dynamic framework

Whenever I have a JavaScript variable that contains HTML printed from a table on my server, I encounter issues when using it in a jQuery function like val(). The problem arises every time someone enters content with special characters like " or '. Thi ...