user1379378
user1379378

Reputation: 59

Show Text on Image Hover

I'm trying to have an image description shown when hovering over the image which is placed in a div (#web01).

I've been toying with the mouseenter/mouseleave and have been able to get text shown but when I link it to a div it doesn't seem to work.

It's probably dead easy but i can't see what I'm doing wrong.

$(document).ready(function () {
    $("#web01").mouseenter(function () {
        $("#titel").html('<p class="titel">description</p>');
    });
    $("#web01").mouseleave(function () {
        $("#titel").html('<p class="titel"></p>');
    });
})

Upvotes: 0

Views: 838

Answers (4)

What have you tried
What have you tried

Reputation: 11138

Assuming you meant to name your element title1 and not titel1 (spelled incorrectly), simply changing the id to title1 fixes the problem. I've given a working example below.

Working Example

Upvotes: 1

fergatron
fergatron

Reputation: 13

In the example on http://api.jquery.com/mouseenter/ I saw them use this in the function.

$(document).ready(function(){
 $("#web01").mouseenter(function(){
  $("#titel",this).html('description'); 
 });

 $("#web01").mouseleave(function() { 
  $("#titel",this).html(''); 
 });
});

Upvotes: 0

Ahmed El Kilani
Ahmed El Kilani

Reputation: 345

I think you need something like this:

http://jqueryui.com/tooltip/

Upvotes: 1

colestrode
colestrode

Reputation: 10658

<div id="web01" title="myTitle">...</div> or <img src="..." title="myTitle"/> will show the native browser title (tooltip).

Upvotes: 0

Related Questions