Incorporating a .png file for hover effects

I've been trying to set up a tooltip that displays a png image when I hover over a section of a CSS map. Unfortunately, my attempts thus far have been unsuccessful.

Every time I try to insert the image, it either causes the tooltip to disappear entirely, display as "undefined," or fail to find the image I'm attempting to include.

document.addEventListener('mouseover', function (e) {
  if (e.target.tagName == 'path') {
    var content = e.target.dataset.name;
    mapDetails.innerHTML = content;
    mapDetails.innerHTML = `<img src="image.png" alt="text for image"/>`
    mapDetails.style.opacity = "100%";
  }
  else {
    mapDetails.style.opacity = "0%";
  }
});

Answer №1

Uncertain about the exact approach you wish to take, but here is a possible solution: https://jsfiddle.net/3t8nvk2s/

<div class="tooltip">Hover over me
  <span class="tooltiptext">Tooltip content</span>
  <span class="image">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>

$(document).ready(function(){
      $(".tooltip").hover(function() {
          $('.tooltiptext').append('<div class="line"><img src="image.png" alt="image"/></div>');
      }, function() {
          $('.tooltiptext').children('.line').remove();
      });
});

</script>

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

Using Vue.js method passing an argument and setting a delay with setTimeout function

I'm struggling to understand why this particular code is functioning as it should. data: { return { userMinerals: 0, mineralsLimit: 1000, miners: 0, superMiner: 0, minerPrice: 10, superMinerPrice: 1 ...

Optimizing jqGrid: Enhancing saveRow function to properly synchronize with editRow function

Exploring how to customize jqGrid's add function for my own needs. I have a navButton with specific requirements: When the user clicks the button, a new row in edit mode should appear on the grid. Once the user enters data and presses enter, the dat ...

Tips on creating a dropdown menu with a fontawesome icon

I'm brand new to coding and struggling to create a drop-down menu similar to the one used in fonawsome fa fa-ellipsis-v While I'm attempting to code it here, I'm not sure why the class is being overridden. *{ margin: 0; padding : ...

iOS button on mobile Safari in the down state

Is there a way to customize the appearance of buttons in Mobile Safari so that they show my specified "down" (:active) state instead of the default semitransparent overlay when touched? ...

Generate a custom JavaScript file designed for compatibility with multiple servers

I am looking to develop a JavaScript file that can be easily added to other websites, allowing them to access functions within my database using an API similar to the Facebook like button. This API should display the total likes and show which friends have ...

What is the most efficient way to minimize the use of if statements in an Angular component when calling a specific function?

Currently, I am working on an Angular 7 temperature conversion application. Within my formGroup, there are inputs and outputs along with two multi-select dropdowns where users can choose the unit of temperature 'From' and 'To' for conve ...

Retrieve the content entered in a form text field without needing to officially submit the form

Is it possible to submit the text box value (partnumber) as a query string in a hyperlink without submitting the form itself? I have been trying to achieve this by using document.getElementById("partnumber").value but keep getting an error "Object Required ...

What is the proper method for filling a custom shape that has been created in Canvas?

I am attempting to create a custom shape, but I am facing an issue where using moveTo prevents me from filling it. Is there any method to determine points on the screen to fill a shape? Or should I use or draw another real shape in the same layer block? T ...

Close the Bootstrap Modal by clicking the back button within SweetAlert

**How can I close a Bootstrap modal when clicking the back button in SweetAlert? I have tried using modal.hide() but it's not working. I am using Bootstrap version 5 and even checked their documentation with no luck. Does anyone know how to achieve th ...

Sort various divs using a list

I have multiple divs containing different content. On the left side, there is a list of various categories. When a category is clicked, I want to display the corresponding div for that category. Initially, I want the main category to be loaded, with no opt ...

The issue of unselection not functioning properly for multiple items when using both selectable and draggable features

i need the unselection of list items to be as smooth as selectable() but without draggable() My desired outcome is similar to the following gif showcasing combined selectable and draggable functionality: https://i.stack.imgur.com/3GjTD.gif here's t ...

Changing video tag's source dynamically using ajax

In my html page, there is a calendar, a video tag, and a button. The button triggers an ajax call to retrieve a video file path from Django based on the selected timestamp. When the page is initially loaded or refreshed, selecting a date and time and click ...

How to disable the Rubber/Elastic scrolling feature on your iPad?

On my webpage, there is a combination of vertical and horizontal scrolling. Everything works fine when the user swipes left or right exactly, but issues arise when the swipe is not precise along a straight line (diagonally). In this case, both vertical and ...

Converting and downloading CSV to XLSX directly from the front end using TypeScript and React

After successfully converting a JSON response to CSV format for download using the function below, I am now looking to achieve the same functionality but with xlsx files on the front end. The current function works well for CSV files and handles Japanese ...

Divs are unable to be positioned at the top of the container

I am struggling with the alignment of blocks inside a container that can be dragged and re-sized within their container. The default position should have 7 divs side-by-side at the top of the container, however, they are appearing stacked on top of each ...

Issues with plugins in Rails 4 are causing functionality to not be operating

I recently installed a template and encountered an issue with some of the JavaScript functionality. However, upon checking the compiled list of JavaScript files, I can see that all the files have loaded successfully and the CSS includes all the necessary f ...

Troubles with HTML, CSS, and jQuery Double-Level Menu

After creating a simplified version of an HTML, CSS, jQuery navigation menu, I noticed that the submenu items were being considered part of the containing list item. This caused them to not function as intended when clicked because they were being treated ...

Changing the input to uppercase within Vue.js

I am looking to capitalize the input data from the user's full name model and would prefer if it is in Latin letters only. Utilizing Vue.js for Uppercase Conversion <p-input :value="value" @input="$emit('input', $event)&qu ...

Having Trouble with the Background Video Scaling on My HTML Bootstrap Page for Mobile Devices

I have been working on an HTML background video page, and everything seems to be working perfectly on desktop. However, when it comes to mobile, the video does not cover the full screen. Only half of the video is visible on the mobile screen. Here is the ...

"Encountering issues when trying to retrieve a global variable in TypeScript

Currently facing an issue with my code. I declared the markers variable inside a class to make it global and accessible throughout the class. However, I am able to access markers inside initMap but encountering difficulties accessing it within the function ...