My dilemma lies in attempting to display a <div> when I hover over a different <a> element. What could be causing this issue?

I have tried numerous solutions to this issue on the website and have incorporated the recommended techniques, but I still can't figure out what's missing. Could it be a larger code structure that is hindering my progress or am I simply overlooking something? Is it possible that another action, such as hover over <a>, is conflicting with this?

The relevant code snippet is as follows:

.box2{
  display:none;
}

a{
border-bottom:1px dotted;
}

a:hover{
border-bottom:1px solid;
}

.topics:hover + .box2{
  display:flex;
}
<p>... interested in a <a class="topics">wide array of topics</a> ... </p>
<div class="box2">A list of topics</div>

https://codepen.io/brxtn/pen/KKKKzXy

<!---GRAIN JAVA START--->

// Java script for grain effect

 Some Javascript code goes here...

<!---LEAF JAVA START--->

// Java script for leaf animation

 Some more JavaScript code related to leaf animation...

<html>

<head>
  // Linking external fonts
</head>

<body>
  // Body content including canvas elements, boxes, links, etc.

</body>

</html>
/*CSS Code*/

body {
  Some CSS styling properties...
}

Answer №1

If I were to add this feature, here is the script I would use:

Important Note:

<a data-target="quarentine" href="/quarantine.html">quarantine</a>

const hover = function(element, isHovering) {
  if (element.tagName.toUpperCase() === "A") {
    const targetId = element.getAttribute("data-target");
    if (targetId) {
      const targetDiv = document.getElementById(targetId);
      if (targetDiv) targetDiv.classList.toggle("show", isHovering)
    }
  }
};

document.querySelector(".menu")
  .addEventListener("mouseover",function(event) { hover(event.target,true) })
document.querySelector(".menu")  
  .addEventListener("mouseout",function(event) { hover(event.target) })  

/* GRAIN JAVASCRIPT START */

var viewWidth,
  viewHeight,
  canvas = document.getElementById("canvas"),
  context;

// change these settings
var patternSize = 64,
  patternScaleX = 1,
  patternScaleY = 1,
  patternRefreshInterval = 4,
  patternAlpha = 25; // int between 0 and 255,

var patternPixelDataLength = patternSize * patternSize * 4,
  patternCanvas,
  patternContext,
  patternData,
  frame = 0;

window.onload = function() {
  initCanvas();
  initGrain();
  requestAnimationFrame(loop);
};

// create a canvas for rendering the grain
function initCanvas() {
  viewWidth = canvas.width = canvas.clientWidth;
  viewHeight = canvas.height = canvas.clientHeight;
  context = canvas.getContext('2d');
  context.scale(patternScaleX, patternScaleY);
}

// create a canvas to be used as a pattern
function initGrain() {
  patternCanvas = document.createElement('canvas');
  patternCanvas.width = patternSize;
  patternCanvas.height = patternSize;
  patternContext = patternCanvas.getContext('2d');
  patternData = patternContext.createImageData(patternSize, patternSize);
}

// fill every pixel of the pattern with a random shade of gray
function update() {
  var value;

  for (var i = 0; i < patternPixelDataLength; i += 4) {
    value = (Math.random() * 255) | 0;

    patternData.data[i] = value;
    patternData.data[i + 1] = value;
    patternData.data[i + 2] = value;
    patternData.data[i + 3] = patternAlpha;
  }

  patternContext.putImageData(patternData, 0, 0);
}

// fill the canvas using the pattern
function draw() {
  context.clearRect(0, 0, viewWidth, viewHeight);

  context.fillStyle = context.createPattern(patternCanvas, 'repeat');
  context.fillRect(0, 0, viewWidth, viewHeight);
}

function loop() {
  if (++frame % patternRefreshInterval === 0) {
    update();
    draw();
  }

  requestAnimationFrame(loop);
}

/* GRAIN JAVASCRIPT END */



/* LEAF JAVASCRIPT START */

let leafVisible = false;

const toggleLeaf = () => {
  if (!leafVisible) {
    document.querySelector(".scale-in-hor-left").style.display = "block";
    leafVisible = true;
  } else {
    document.querySelector(".scale-in-hor-left").style.display = "none";
    leafVisible = false;
  }
}

document.querySelector("#menuleaf").addEventListener("click", toggleLeaf);

/* LEAF JAVASCRIPT END */

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 it possible to change the title of a QGroupBox using HTML expressions in Python?

Does anyone know how to set the title of a QGroupBox with HTML expressions in a Python program? For example, using ABC for subscript. If you have any insights or solutions, please share! Thank you. ...

What is the best way to apply a border to the entire vertical line in a Bootstrap table?

I have utilized bootstrap to create the table displayed below. View image here I am looking to incorporate a vertical red line similar to the one shown in the image below. Additionally, I would like to add a drop shadow along with the red line. View ima ...

When using HTML and PHP, do note that the function mysql_fetch_array() requires the first parameter to be a resource and

I'm currently working on developing a feature for our website that allows users to search for banned usernames on our servers. The idea is to create a simple form where users can enter the username they want to check and then display any matching resu ...

Getting the dimensions of an image when clicking on a link

Trying to retrieve width and height of an image from this link. <a id="CloudThumb_id_1" class="cloud-zoom-gallery" rel="useZoom: 'zoom1', smallImage: 'http://www.example.com/598441_l2.jpg'" onclick="return theFunction();" href="http ...

Issue with the close button on ngb-alert not functioning properly

As I develop my website, I have incorporated an ngb-alert component to display an alert message to users upon login. While the alert itself is functioning properly, I have encountered an issue with the close button being misaligned, and I am struggling to ...

Is there a way to program custom key assignments for my calculator using JavaScript?

As a beginner in the world of coding and JavaScript, I decided to challenge myself by creating a calculator. It's been going smoothly up until this point: My inquiry is centered around incorporating keys into my calculator functionality. Currently, th ...

One problem with placing Bootstrap columns inside another column

Currently, I am in the process of working on a website that requires a description section. To achieve this, I decided to use two Bootstrap columns – one with a size of 8 and another with a size of 4, totaling up to 12 grid units. Inside the column sized ...

Can you please tell me the name of this specific graph? And could you explain how I can recreate it on a

I am fully aware that this information is just a Google search away. However, I am unsure of the specific name of the chart I am seeking. Therefore, I am unable to conduct an effective search for suitable plugins or APIs. Your understanding is greatly appr ...

The orientation of the navbar is set to vertical rather than horizontal

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script> <div id="navigation"> ...

Transmitting JSP form data through email via POST method

I have a question that I'm struggling to find the answer to online. I created a basic HTML form within a JSP that includes a 'Enter name' text box and a submit button. I want to know if there's a way to automatically send the POST infor ...

Display a color picker within an HTML div with fixed positioning to prevent scrolling within the element

Within a div, I have text boxes that trigger a color picker to be displayed when clicked. Currently, the color picker appears at the bottom of the text box, but I would like it to be positioned on the left or top without requiring scrolling. Can anyone a ...

Issue with ng-pattern validation not functioning correctly on textarea in AngularJS

Attempting to validate a textarea that, if valid, will enable a specific button. Utilizing ngPattern for validation but encountering issues with implementation. Referencing the example code below: <div ng-app="test"> <form name="theForm" ng-contr ...

The functionality of scrolling in Angular Material tabs is not functioning properly

I have encountered a challenge while working with angularjs material design. The md-scroll functionality is not working as expected for scrolling up and down, even though it works fine for left and right scrolling. In a tab with a table view, the vertical ...

What steps are needed to adjust a modal window so that it perfectly fits the size of the image it contains?

I am currently utilizing Bootstrap 4.2 to create a popup window (modal) featuring an image displayed at its real size (100%) in both width and height, provided that the browser window size permits. If the image surpasses the window dimensions, it should au ...

Unique Tags and Javascript: A customized approach

In the process of developing a web application, I am aiming for high standardization. To achieve this goal, I plan to utilize custom namespace tags that will be modified by JavaScript based on their functionality. For instance: <script type="text/java ...

I am looking to implement a feature in my quiz application where a green tick mark appears next to the question number for the correct answer and a red cross mark for the wrong answer

My HTML code here retrieves questions from a database and displays them based on the question number. <h4>{{indexOfelement+1}}</h4>&nbsp;&nbsp; In my CSS, I need to style the questions as follows: How can I achieve this? Each question ...

Conflict between the top menu and body on the HTML page is causing issues

Encountered an issue with my HTML code: CSS: .fixedmenu { overflow: hidden; background-color:rgb(153,0,51); position: fixed; /* Ensures the navbar stays in place */ top: 0; /* Positions it at the top of the page */ width: 100%; /* Occ ...

Sorting Json Data Using Vue

My experience with Vue.js led me to a challenge I can't quite figure out: how to filter specific data in a Json file. Let me provide more context: I have a Json file filled with various electronics products such as computers, mice, keyboards, etc. I w ...

Animating elements with CSS keyframes for scaling and translating transformations

I'm having trouble manipulating the size and position of an absolutely positioned div. Even after scaling, the div doesn't end up where I intended it to be in my keyframe animation. I suspect that this issue is caused by the fixed coordinates of ...

Ways to contrast HTML without considering whitespace?

I'm currently testing an HTML builder through unit testing. My goal is to confirm that the output content matches the expected content, while allowing for some leniency when it comes to white space. More specifically, I am not concerned with whether ...