views:

86

answers:

2

The below code works but on mouse enter causes flicker

     $("#helptext").bind("mouseenter",function(){
         $("p:first",this).text("helptext.");
       }).bind("mouseleave",function(){
         $("p:first",this).text("");
       });

The below code does not work

  /*
     $("helptext").mouseout(function(){
         $("p:first",this).text("sdlfksdlfjskldjl");
       }).mouseover(function(){
         $("p:first",this).text("mouse over");
       });*/

I want to remove the flicker or get the second code working.

The HTML for above

<div id="helptext"><img  alt="Help Text" src="/static/help.png"></img><p></p></div>
A: 

This may be kind of obvious, but isn't the piece of code that isn't working missing a # in the first line? Seems like it should be:

$("#helptext").mouseout(function(){
    $("p:first",this).text("sdlfksdlfjskldjl");
}).mouseover(function(){
    $("p:first",this).text("mouse over");
});
Nikolas Stephan
yes, that was an obvious typo. Thank you for pointing it out.
dhaval
A: 

I suggest using hover() this instead of binding to mouseenter and mouseleave looks cleaner to me.

$("#helptext").hover(function(){
    $("p:first",this).text("helptext text.");
  }, function(){
    $("p:first",this).text("");
  }
);

Btw. I guess without more of your HTML/CSS code I think we can't solve this issue as the above doesn't flicker for me at all.

Check here http://jsbin.com/ihuna/

jitter
very cute picture ;-) and thanx for demo site, very kind of you. It works for you because the length of help text is less than div width. It was flickering for me because the length of text was more. Please check and let me know if my assumptions are right.
dhaval
Check new link. Still doesn't flicker for me.
jitter