Solved

Jquery display custom text on hover

Posted on 2011-03-03
1
451 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now