Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Jquery display custom text on hover

Posted on 2011-03-03
1
Medium Priority
?
459 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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

927 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