Dynamic navigation - main menu featuring a hyperlink

I am facing a scenario where I need to redirect the parent menu to a link instead of displaying the sub-menu. Currently, I am using Slick Menu http://slicknav.com/

It makes sense that the parent menu should not be linked to show the child menu on mobile devices. On desktop versions, we can utilize hover effects to display sub-menus, and clicking on the parent menu can also open the link. However, on small screens, we need to decide whether to open the link or show the submenu.

My current issue is in the fiddle example (http://jsfiddle.net/y1dLdd1f/1/) where I have linked Parent 1 menu to google.com, but the script is preventing this action. How can I unblock it so that when a user clicks on it, the page opens instead of showing the sub-menu if the parent menu has a valid link?

<ul id="menu">
    <li><a href="http://www.google.com">Parent 1</a>
        <ul>
            <li><a href="#">item 3</a></li>
            <li>Parent 3
                <ul>
                    <li><a href="#">item 8</a></li>
                    <li><a href="#">item 9</a></li>
                    <li><a href="#">item 10</a></li>
                </ul>
            </li>
            <li><a href="#">item 4</a></li>
        </ul>
    </li>
    <li><a href="#">item 1</a></li>
    <li>non-link item</li>
    <li>Parent 2
        <ul>
            <li><a href="#">item 5</a></li>
            <li><a href="#">item 6</a></li>
            <li><a href="#">item 7</a></li>
        </ul>
    </li>
</ul>

Answer №1

Slick menu offers various options, one of which is "allowParentLinks". To implement this, all you need to do is...

$(document).ready(function(){
    $('#menu').slicknav({
        allowParentLinks:"true"
    });
});

To demonstrate this in JSFiddle, make sure to include target="_blank" in your <a> tag.

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

Encountering a critical issue with Angular 12: FATAL ERROR - The mark-compacts are not working effectively near the heap limit, leading to an allocation failure due

After upgrading my Angular application from version 8 to 12, I encountered an issue. Previously, when I ran ng serve, the application would start the server without any errors. However, after updating to v12, I started receiving an error when I attempted t ...

Inquiring about the intricacies of using Regular Expressions in

Can anyone provide a regex that only allows the characters 0-9, a-z, A-Z, hyphen, question mark, and "/" slash, with a character length between 5 to 15? I attempted the following approach, but it did not yield the desired result: var reg3 = /^([a-zA-Z0-9? ...

Can the value of a key automatically default to the parent's value if it is not found in the child?

When looking at the JSON example provided, is there a method to automatically switch back to the parent object key if the child object does not contain the key? // Example of i18n JSON "parent": { "foo": "foo", "bar": "bar", "child" ...

Angular: Only display array objects that do not contain the "deactivated" key

My array of objects is generated through JSON and it has a specific structure: {"uid":1,"first_name":"Name","last_name":"Surname","sex":1}, {"uid":2,"first_name":"Name","last_name":"Surname","sex":2}, {"uid":3,"first_name":"Name","last_name":"Surname","de ...

Troubleshooting Problems with React-Scroll Link Element in Navigation Bar

Having trouble implementing a hover effect on my navigation links using the Link component from the react-scroll library. The desired effect is for the links to increase in size when hovered over by using transform: scale(1.1). Unfortunately, the effect is ...

"Encountering a 'Cannot GET' error message while utilizing Rest API in Node.js

Currently, I am developing a project using nodejs along with the expressjs framework. My focus right now is on setting up and running a "Rest Api," but I seem to be encountering an error message that reads: Cannot GET /published Let me share my routes fil ...

What's the best way to switch between colors in a Vue list?

I have a custom tree-view component that I'm working on: <template> <li class="main__li list" :style="{'margin-left': `${depth * 20}px` ,'background-color': `${col}`}" @click="toggle(e); getEl( ...

Watching the $scope variable using $watch will result in triggering even when ng-if directive is used, displaying

Encountering an unusual behavior in AngularJS that may appear to be a bug, but there could be a logical explanation. A certain value is being passed to a directive as an attribute. Within this directive, the parameter is being watched using $scope.$watch. ...

Ways to enhance the capabilities of the Javascript Date object

I'm attempting to create a subclass or extension of the native Date object without making any modifications to the original object. Here's my first approach: var utilities = require('utilities'); function CustomDate() { ...

The client sends a request to the server to execute a Python script

I've been grappling with this question as a newbie for quite some time now.. I'm in the process of developing a web application using nodejs. Below is my app.js file to kickstart (my server-side) http = require("http"), path = require( ...

npm's protocol for handling callback errors

While exploring the coding style guidelines by npm, I stumbled upon a rather enigmatic suggestion: Be very careful never to ever ever throw anything. It’s worse than useless. Just send the error message back as the first argument to the callback. Thi ...

Create static HTML web pages using information from a text file

Exploring a new concept of a random joke generator that loads a unique html page with a quirky joke every time. Currently, the main index page is structured like this: <!DOCTYPE html> <html> <head><title>Jokes</title> ...

Proper method for verifying line-clamp in a Vue component

I came across a question that aligns perfectly with my current task - determining if text is truncated or not. The query can be found here: How can I check whether line-clamp is enabled?. It seems like my approach may not be accurate, so any guidance on ho ...

Ways to display Div contents based on selected options in an Angular 2/4 list

"Struggling with dynamically displaying div contents" Situation:- I have a list of 3 items: *Menu1 *Menu2 *Menu3 and I have separate div contents for each of these menu items. Requirement :- By default, Menu1 should be displayed. When Menu2 is clicked, ...

My AngularJs code seems to be throwing some errors

I recently started learning Angularjs and here is the code I have written: <!DOCTYPE html> <html> <head> <title>ng-Messages Service</title> <script src='https://ajax.googleapis.com/ajax/libs/jquery ...

Creating a webpage that loads directly to a specific section of content

After searching online, I couldn't find the solution I was looking for. My goal is to have the visible part of the page load halfway down the actual page. This way, when users visit the site, they can immediately scroll up to see more content. I hope ...

Getting a specific value from a REST API array in JavaScript: Tips and tricks

After being stuck on this problem for 8 hours, I finally decided to seek help: In my JavaScript file, I am attempting to extract data from a REST API response. The response consists of an array of objects structured like this: [{"start":"2017-04-21 14:40 ...

Troubleshooting issue: Inability to make Spring MVC work with Ajax form submission and

Here is the Ajax code snippet: var str = $("#observationForm").serialize(); $.ajax({ type : "post", data : str, url : "updateObservation", async : true, /* dataType : "multipart/form-data", */ success : functio ...

smoothly hide the dropdown menu when a link is clicked with a transition effect

I am struggling with two bugs in my dropdown menu that I can't seem to fix. The navigation links on my homepage take users to different sections of the page instantly when clicked. However, the issue arises when the dropdown menu does not close after ...

Incorporating lazy loading for diverse content to enhance pagination

I'm currently using jpaginate for pagination on a large dataset, but I've noticed that all the content loads at once. Is there a jQuery plugin available that will only load the content for the current page? ...