Jquery: Hover over any paragraph, append div with little message, hover off, it fades out, is this right?

Just use class instead of id: $('p'). Hover(function() { $(this). Append('BOOKMARK THIS') $('.

Both'). Animate({opacity: 1.0}) }, function(){ $('. Both').

FadeOut(600, function(){ $(this).remove() }) }); jsfiddle.net/yzXxH.

I'd probably change it a little: $('p'). Hover(function() { $('BOOKMARK THIS') . AppendTo(this) .

Animate({opacity: 1.0}) }, function(){ var both = $(this). Find('span. Both'); both.

FadeOut(600, function(){ both.remove() }); }); The reason I used a class instead of an id is that when you leave one paragraph and enter the next, you're going to temporarily have two of these spans — the one that's fading out on the old paragraph and the one added to the new one. Having two elements with the same id is invalid and fraught with peril. I'd probably also cancel the animation early if I come back to the same paragraph: $('p').

Hover(function() { $(this). Find('span. Both').stop().remove(); // Stop and remove it if it's there $('BOOKMARK THIS') .

AppendTo(this) . Animate({opacity: 1.0}) }, function(){ var both = $(this). Find('span.

Both'); both. FadeOut(600, function(){ both.remove() }); }).

It doesn't look to me like you have a need to keep adidng and removing to the dom. Just put the span in by default with style="display:none;", then $('p'). Hover(function() { $(this).

Find('#both'). Animate({opacity: 1.0}) }, function(){ $(this). Find('#both').

FadeOut(600) }); That won't work exactly, you may have to mess with opacity in the default style to get what you want. Still, no need to manipulate the dom.

Problem is the repeated span is in the HTML, sometimes read by vocal browsers, search engine robots and so on. And I'm not talking about the size issue if you have several P. Appending the span each time is less extensive than adding it to the source code.

– Capsule Feb 18 at 10:52 @Capsule To be sure there are cases where ou want to manipulate the dom, such as the reasons you give. But from the OP's question and example code, I don't think this one of them, and I think its good practice to always use the simplest solution allowed by the problem. – Matt Feb 18 at 12:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions