Solved

Jquery display custom text on hover

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

808 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