Solved

Jquery display custom text on hover

Posted on 2011-03-03
1
456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

630 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