Solved

Jquery display custom text on hover

Posted on 2011-03-03
1
453 Views
Last Modified: 2012-05-11
The goal is when you hover over anything with the class "Edit" it will display certain text in the "ContentFooter" div.

So I have an image like this:

<img class="Edit" toast="This is the message to display" src="../image.png">

When I hover over it, it will display the alert "test1" (when it's uncommented).  However, the alert of $(this).attr('toast').text() does not work.  I have tried .val() as well.  I am new to jquery.
$(".Edit").hover(
    function () {
        //alert("test1");
        alert($(this).attr('toast').text());
        //$(".ContentFooter").html($(this).attr('toast').text());
    },
    function () {
        $(".ContentFooter").html("");
    });

Open in new window

0
Comment
Question by:Cerixus
1 Comment
 
LVL 8

Accepted Solution

by:
McNetic earned 500 total points
ID: 35030762
The text() call is wrong. This method is for getting the text content of elements, not the value of attributes. You already get that by attr(). So, correctly, it has to be:
$(".Edit").hover(
    function () {
        $(".ContentFooter").html($(this).attr('toast'));
    },
    function () {
        $(".ContentFooter").html("");
    });

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question