Continuous updates triggered by mouse movement with jQuery

Can someone help me figure out why my custom description isn't following my mouse pointer during the 'mousemove' event on an image?

I've provided the HTML code below:

<!DOCTYPE html>
<html lang="en>
    <head>
         <title>
         </title>
         <meta charset="utf-8" />
         <link rel="stylesheet" type="text/css" href="css/custom.css" />
    </head>
    <body>
        <div>
            <img src="images/wolwerine.jpg" alt="Wolverine" hovermytext="She is doubting my capabilities." class="wolverineClass" id="wolverineId" />
        </div>  
        <div class="wolverineHoverText">
        </div>      
    <script type="text/javascript" src="js/jquery-3.1.1.min.js" ></script>
    <script type="text/javascript" src="js/custom.js" ></script>
    </body>
</html> 

Check out the custom CSS code below:

.wolverineHoverText{
    height: 40px;
    width: 300px;
    position: absolute;
    padding: 40px 80px;
    border: 1px solid #106c90;
    background: #da8808;
    display: none;
    color: #ffffff; 
    font-size: 20px;
    top:20px;
    left:20px;
}
img{
    height: 600px;
    width: 900px;
    opacity: 0.5;
}

And here is the jQuery code snippet from custom.js:

$(document).ready(function(){
    $('.wolverineClass').mousemove(function(y){
        var x = $(this).attr('hovermytext');
        $('#wolverineHoverText').text(x).show();
        $('#wolverineHoverText').css('top',y.clientY+10).css('left',y.clientX+10);
    }).mouseout(function(){
            $('#wolverineHoverText').hide();
        });
});

If you have any doubts or suggestions, drop a comment below!

Answer №1

Check out this effective solution for your needs!

$(document).ready(function(){
    $('.wolverineClass').mousemove(function(y){
        var x = $(this).attr('hovermytext');
        $('#wolverineHoverText').text(x);
        $('#wolverineHoverText').css('top',y.clientY+10).css('left',y.clientX+10).show();
    }).mouseout(function(){
            $('#wolverineHoverText').hide();
        });
});
.wolverineHoverText{
    height: 40px;
    width: 300px;
    position: absolute;
    padding: 40px 80px;
    border: 1px solid #106c90;
    background: #da8808;
    display: none;
    color: #ffffff; 
    font-size: 20px;
    top:20px;
    left:20px;
}
img{
    height: 150px;
    width: 400px;
    opacity: 0.5;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
 
<div>
   <img src="images/wolwerine.jpg" alt="Wolverine" hovermytext="She is doubting my capabilities." class="wolverineClass" id="wolverineId" />
</div>  
<div id="wolverineHoverText" style="display:none"></div>

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

Use the 'url' parameter to pass into the ajax function when using jQuery for online requests

I am working with an ajax code that retrieves data from an XML file locally. <script> function myFunction() { $("#dvContent").append("<ul></ul>"); $.ajax({ type: "GET", url: "test.xml", ...

Disappearing a button once the limit is met: Utilizing Jquery

There is a button that allows users to View More Friends in groups of 16: <button class="cancel auto-btn hide-btn" id="viewAllFriends" style="display: visible;">View All Friends</button> The button's initial display setup is as follows: ...

Sending data with the request body using Express and Passport

I've created a login application using Express and Passport, but I'm having trouble directing the user to their specific user profile page. The goal is for users to fill out an HTML form and then be redirected to their own profile page (which dif ...

Reverting to the original order in jQuery DataTables after dropping a row

Recently, I've been attempting to utilize jQuery DataTables in conjunction with the Row Ordering plugin. At first, everything seemed to be functioning properly until a javascript error popped up indicating an unrecognized expression. After researching ...

Combining Rails 4 with coffeescript while encountering an issue with the jQuery sortable detatch functionality

Currently, I am using Ruby on Rails 4 along with the jquery-ui-rails gem. Within my application, there are certain lists that have a sortable jQuery function implemented. $ -> $('#projects').sortable handle: '.handle' ...

Creating atomic controller actions in Sails.js: A guide to optimizing your controller functions

If I am looking to perform multiple operations within a Sails.js controller, how can I ensure that these actions are atomic to maintain the correctness of the results? This includes not only database operations but also various Javascript processing tasks. ...

Tips for concealing the final click (add) tab after it has been clicked and revealing the hidden (add) button when the user clicks on the remove button

I have created a form where users can add tests. Everything is working smoothly but I want the previous "Add Another Test" field to be removed when the user clicks on it and a new field to be shown. Everything is running well, but the issue is that when t ...

What is the best way to assign a unique ID to every <td> element within a table using React Js?

Hello everyone. I am currently working on assigning unique ids to each td in a table based on data received through an API. This is what my code looks like so far. CodeSandbox const assignIdsToTableData = (data) => { var items = Object.values(data)[0 ...

The array's value fluctuates into a negative without any direct manipulation from my end

In order to work with the $scope.option value, I stored it in a temporary variable and then applied operations on the temporary variable after changing all the values of $scope.option to negative numbers. var app = angular.module('myApp', []); ...

Utilizing the require pattern to integrate JavaScript functionality into HTML

Have: project |- consume_script.js |- index.html Need index.html to be like: <html> <head> </head> <body> <script src="consume_script.js"></script> </body> </html> Issue: consume_script ...

The process of sending parameters to an API in ReactJS: a guide

My objective is to target .....the values originating from login (can be anything)-> for example email:'[email protected]' password:'12345678' I am required to extract the username until "@" and use it as a username i ...

Steps for retrieving user timezone offset and transmitting it to the server in an ASP.net application

I need assistance with capturing and sending a user's timezone or offset when they successfully sign in. I came across the "getTimezoneOffset" method in JavaScript, but I'm unsure how to automatically send this data without the user explicitly in ...

When using jsPlumb's beforeDrop function alongside ngToast, the message may not display immediately

I have been working on a project where I am integrating the jsPlumb library to create a node-based interface. jsPlumb provides an event called 'beforeDrop' which is triggered before connecting two endpoints. I plan to use this event to check a c ...

Can someone explain why Array.from(classList)[0] is not changing to 'className'?

HTML Design <div class="custom-container color-red"> <h3>Hello, I am a customized container</h3> </div> Javascript Logic let element = document.getElementsByClassName('custom-container')[0]; let clas ...

jQuery's resize() function is not functioning properly

I have a question about resizing my menu items using jQuery. Currently, I am successfully able to resize the list items when the page is reduced in size. However, when I try to increase the page size, the list items do not decrease accordingly. Is there a ...

In what ways can you shut down an electron application using JavaScript?

My Electron app is running an express server. Here is the main.js code: const electron = require("electron"), app = electron.app, BrowserWindow = electron.BrowserWindow; let mainWindow; function createWindow () { ma ...

The type 'Dispatch<SetStateAction<boolean>>' cannot be assigned to type 'boolean'

Currently, I am attempting to transfer a boolean value received from an onChange function to a state variable. let [toggleCheck, setToggleCheck] =useState(false);` <input type="checkbox" id={"layout_toggle"} defaultChecked={toggleCh ...

The system is unable to locate the module at 'C:UsersSanjaiAppDataRoaming pm ode_modulesprotractorinprotractor'. This error originates from internal/modules/cjs/loader.js at line 960

After running "protractor conf.js" without any issues, I decided to install protractor globally using the command "npm install -g protractor". However, after installing protractor globally, I encountered the following error message: internal/modules/cjs/lo ...

The array of objects has vanished into thin air

I am receiving a JSON string from my server through a PHP file, which contains 25 meals. The PHP script is initiated by a JavaScript function. My goal is to convert the JSON into an array of objects. The response stream displays the correct values and eac ...

transfer data to the controller using ajax

I've been curious about the distinction between these two syntaxes: var value = $("#myForm").serialize(); $.ajax({ type: "post", url: "testMethod", data: value }); and var value = $("#myForm").serialize(); $.ajax({ type: "p ...