How come inactive links are still able to be clicked on?

I have been experimenting with various methods to disable links, but I seem to be unable to prevent them from being clickable. While I was successful in changing the cursor to 'not-allowed' when hovering over the disabled link, it still remains clickable. I've referenced resources like this one and this sample, but none of the solutions seem to work for me. Even after checking multiple sources, I can't figure out what I'm doing wrong.

 /***** entire navigation bar *****/
nav#prime {
  display: grid;
  place-items: center;
  font-family: "Gill Sans", sans-serif;
  font-size: 14.75px;
}
nav#prime ul {  
  grid-auto-flow: column;
  list-style: none;
  text-align: center;
  padding: 0;
  margin: 0;
}
nav#prime li { 
  margin: 0;
  padding: 0;
  position: relative;  
}

/***** links *****/
ul#navbar a:link
  Display:block;
  Text-decoration:none;
  Background-color:#0E0E10;
  Color:#FFFAFA;
  Margin:0;
  Padding:5px 11px;
}
ul#navbar a:visited {
  Background-color:#F5F5F5;
  Color:#1A1110;
}
... (CSS code continues)

<nav id="prime">
    <ul id="navbar">
        <li class="dropdown">
            <button type="button" onclick="myFunction()" class="dropbtn">The Desi Ghost Hunters
                <i class="caret-down"></i>
            </button>
            <ul class="sub-menu">
                <li class="suboption"><a href="#" title="Siddharth Bantval">Siddharth Bantval</a></li>
                ... (HTML code continues)

Answer №1

To achieve this, you can utilize the CSS property pointer-events: none;. This allows you to still trigger actions using event listeners, while disabling regular clicking functionality.

If you want to disable all mouse functions for a link, wrap it in a div tag and apply the cursor property as needed.

Check out the MDN documentation for the pointer-events property

/***** styling for navigation bar *****/

nav#prime a {
  pointer-events: none;
}

nav#prime {
  display: grid;
  place-items: center;
  font-family: "Gill Sans", sans-serif;
  font-size: 14.75px;
}
nav#prime ul {  
  grid-auto-flow: column;
  list-style: none;
  text-align: center;
  padding: 0;
  margin: 0;
}
nav#prime li { 
  margin: 0;
  padding: 0;
  position: relative;  
}

/***** styling for links *****/
ul#navbar a:link {
  display: block;
  text-decoration: none;
  background-color: #0E0E10; 
  color: #FFFAFA; 
  margin: 0;
  padding: 5px 11px;
}
ul#navbar a:visited {
  background-color: #F5F5F5; 
  color: #1A1110; 
}
ul#navbar a:hover {
  background-color: #242124; 
  color: #FFFFF0; 
}
ul#navbar a:active {
  background-color: #D3D3D3;
  color: #808080;
}

/***** styling for buttons *****/
button.dropbtn {
  outline: none;
  border: none;
  font: inherit; 
  background-color: #0E0E10; 
  color: #FFFAFA; 
  margin: 0; 
  padding: 5px 11px;
}

/***** submenu positioning *****/
#navbar ul {
  position: absolute;
  white-space: nowrap;
  z-index: 1;
  left: -99999em;
}

#navbar>li:hover>ul {
 
  position: absolute; 
  top: 100%;
  width: 100%;
  left: 0;
  background: #fff;
  border: 1px solid #000;
}

#navbar>li:hover>li li:hover>ul {
  left: 100%;
  margin-left: 1px;
}

/***** first tier *****/
#navbar {
  border: 1px solid;
  border-color: #0E0E10;
  border-radius: 4px;
  background-color: #0E0E10;
}
#navbar>li {
  float: left; 
}
<nav id="prime">
    <ul id="navbar">
        <li class="dropdown">
            <button type="button" onclick="myFunction()" class="dropbtn">The Desi Ghost Hunters
                <i class="caret-down"></i>
            </button>
            <ul class="sub-menu">
                <li class="suboption"><a href="#" title="Siddharth Bantval">Siddharth Bantval</a></li>
                <li class="suboption"><a href="https://www.ikerjimenez.com/" target="_blank" title="REAL NAME: Iker Jiménez Elizari">Iker Jiménez</a></li>
                <li class="suboption"><a href="#" title="Gaurav Tiwari">Gaurav Tiwari <span class="cross">&#8225;</span></a></li>
                <li class="suboption"><a href="https://www.youtube.com/channel/UC5RfSq8MS00LWofLPSKAnDA" target="_blank" title="Alberto del Arco">Alberto del Arco</a></li>
                <li class="suboption"><a href="#" title="Alexsander Myagchenkov">Alexsander Myagchenkov</a></li>
                <li class="suboption"><a href="http://chernobrov.narod.ru/" target="_blank" title="Vadim Chernobrov">Vadim Chernobrov <span class="cross">&#8225;</span></li>
                <li class="suboption"><a href="#" title="Meghna Porwal">Meghna Porwal</a></li>
            </ul>
        </li>
    </ul>
</nav>

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

Is there a way to apply an event function after adding elements through append?

When I click the button, a div is appended inside the body. However, I am trying to make it so that when I click on this newly appended div, an alert message pops up. I have tried implementing this with a highlighted area, but have been unsuccessful. How c ...

Delete the current row in the table before adding a new one with jquery

Having a HTML table and performing updates using Ajax. Everything is functioning properly so far. When clicking on the Edit button, the values are displayed in the textboxes correctly. However, when clicking on the Add button, the table is updated accordin ...

What is the best way to remove horizontal scrolling and reduce element size on mobile devices?

My current project is utilizing the Material-ui framework, and I have a situation where numerous anchor elements are being displayed as a table within a Paper component from mui. However, due to the length of this table, it causes a horizontal scroll bar t ...

Get rid of the folder from the URL using an <a> tag

I have both an English and French version of my website located at: *website.com/fr/index.php *website.com/index.php Currently, I have a direct link to switch between the two versions: -website.com/fr/index.php -website.com/index.php. However, I ...

Is there a way to verify if an element possesses a specific style, and if so, alter the style of a different element accordingly?

Could you assist me in achieving a similar effect as demonstrated below: I have two menus (http://osiyo-nur.uz/osiyo-nur.uz/test6/), one of which is initially invisible. When I hover over the first menu, the second menu becomes visible with an overlay eff ...

Clearly define where each navigation bar item should be displayed within your Django application using Bootstrap

I've been attempting to specify the exact page where this navbar dropdown should be displayed. I attempted adding this line: {% if request.resolver_match.url_name == 'club_selection' %} class = "active" {% endif %} but it doesn&ap ...

Issues with IE7 related to Jquery and potentially HTML as well

I am currently working on a website project for a local charity organization, and I am encountering technical issues with compatibility in IE7. The website functions perfectly in all other browsers I have tested, and it even passes the validation process o ...

Prevent scrolling on both md-sidenav and md-content in AngularJS Material

Currently, I am working on a website using AngularJs Material sidenav. My goal is to make both md-sidenav and md-content appear as one page, without any scroll bars showing up when the height of one element exceeds that of the other. How can I achieve th ...

Simple method for extracting data from JSON and saving it into an array with jQuery

I have a JSON file containing the resource "A" and literals "B", "C", and "D". My goal is to extract only the items B, C, and D, convert them into strings, and store them in an array. Below is the script I have written for this purpose: <script> // ...

"Aligning two images side by side in a horizontal

[enter image description here][1]I am trying to place two images on my website, but I am struggling to vertically align them properly. I have attempted using line-height and vertical alignment, however, I cannot seem to pinpoint the issue or identify any m ...

How can I use JQuery to sum up the numbers within div elements?

Is there a way to automatically number the generated blocks? For example, the first block would display "1", the second "2" and so on. Below is my current code. Simply input the desired number of blocks in the input field. <!DOCTYPE html> <html ...

ng-init assign value to a new object

<!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="myCtrl2" ng-init="person = new Person('Al ...

I desire a smooth fade-in transition for the background image when the addClass function is

If the background color is set to header-fixed-position, the color will fade in. However, if the background is an image, the image will not fade in. Apologies for my lack of proficiency in English. Please refer to the sample code below. Try removing the c ...

The attempt to update a div element in HTML using an Ajax function was unsuccessful

My attempt to showcase the search results of my webpage below the search area was unsuccessful. I utilized AJAX to present the outcome in a div, but encountered issues. I have three key components: the div, the search result page, and the AJAX function. ...

Chrome is the only browser that displays the correct number of columns, unlike IE and Firefox

[Link removed] Is anyone else experiencing an issue with the columns on a website layout? I have 5 columns set up with each post taking up 20% width. It looks fine in Chrome, but in IE and Firefox, the last column gets pushed below so there are only 4 col ...

Effectively replicating an HTML action in MVC ASP.NET

I am looking to replicate a basic function in HTML that is currently working for my needs, but now I need to implement the same functionality in MVC ASP.NET. Here is the original HTML code: <HTML> <HEAD> </HEAD> <BODY> ...

Utilizing the NuxtJS framework to tap into video camera functionalities

I am completely new to Vue and NuxtJs. My goal is to create a webcam feature using NuxtJs, but I have encountered some challenges. <template> <div class="photobooth"> <div class="controls"> <button @click="takePhoto">Ta ...

The div above the footer seems to be interfering with the styling of the footer. Is there a solution to

I am currently working on implementing a Help functionality for our users. In order to do this, I have placed a div right above my footer. However, I am facing an issue where the styling of my div is affecting the footer in ways that I cannot figure out. ...

Is the Packery image grid only functional when the background image is specified in CSS and not in JavaScript? Perhaps we need to look into using Await/Sem

I've successfully implemented a packery image grid that is responsive and functional when the background image in the .item-content section is defined in the CSS file: http://codepen.io/anon/pen/eJdapq .item-content { width: 100%; height: 100%; ...

"Placing drop-down animations in just the right spot

I'm currently working on adjusting the dropdown behavior for thumbnails when hovering over them. I want the drop-down to appear beneath the 'Caption Title' instead of above the image, but so far my CSS adjustments haven't been successfu ...