0

I have a problem here. When my mouse hover over a div, a text appear in the div. And when it is on mouseout from the div, the text will disappear. My problem is however when the mouse is over the appeared text, it will treat that it is mouseout from the div, causing the text to disappear. How can i do to avoid that? I want the text to remain as long the mouse is in the div even though it is above the text. Thanks..

<div class="passd"></div>

    $('.passd').live("mouseover", function(){
  if($(this).children('#passopt').length==0){
   $(this).append('<p id="passopt">appear text</p>');
  }
 });
 $('.passd').live("mouseout", function(){
  $(this).children('#passopt').remove();
 });
1
  • i got the problem , we can achieve what you want by using some boolean true or false, but that isnot good approach , let me think and get back... Commented Dec 4, 2010 at 20:51

4 Answers 4

2

Try this:

$('.passd')
    .live("mouseenter", function() {
        $(this).append('<p id="passopt">appear text</p>');
    })
    .live("mouseleave", function() {
        $(this).children('#passopt').remove();
    });

Tested, and works: http://jsfiddle.net/xLzdP/

Sign up to request clarification or add additional context in comments.

Comments

1

you could use the mouseleave event instead...

http://api.jquery.com/mouseleave/

1 Comment

+1 for you gave the soloution , but you would have given some code also , so people like it..
0

Check out http://flowplayer.org/tools/tooltip/index.html to see if it can do what you want...

2 Comments

the problem he is having is mouseover of text is treating as mouseout of div so its hiding the text , we can use the plugin , but we should see how to fix his problem.
sometimes the solution is to use a tool that already has it solved. :)
0

You could achieve just as much with using .hover():

    $('.passd').hover(function() {
        $(this).append('<p id="passopt">appear text</p>');
}, function(){
        $(this).children('#passopt').remove();
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.