2

So I have some HTML like this:

<a class="tooltip" title="my tool tip">
    Hover over me for a tool tip!
</a>

the javascript changes the html into something like this:

<a class="tooltip">
    Hover over me for a tool tip!
    <span style="position:absolute; display:none;">my tool tip</span>
</a>

When hovering over the parent element, the javascript triggers the child element to display. The child element is positioned so that it looks like it is not inside the parent element, so hovering over the child element still causes the child element to be displayed. I want to only show the child element when you are not hovering over it.

How can I do this?

5
  • Could you show the JS code for the hover event? Commented Jul 21, 2011 at 20:42
  • not hovering over the child or the parent? Commented Jul 21, 2011 at 20:42
  • Is zero visibiliy enough or should the user be able to click 'through' the position of the tooltip, on links and the like? Commented Jul 21, 2011 at 20:42
  • I think this would be a lot easier to understand if you put it in a jsfiddle Commented Jul 21, 2011 at 20:43
  • 3
    With display:none, there shouldn't BE anything to hover over in the child element. Commented Jul 21, 2011 at 20:43

2 Answers 2

3

Use event delegation:

$('.tooltip').hover(function(e){
    if($(e.target).is('span')){
        // your child span is being hovered over
        e.stopPropagation();
    }else if($(e.target).is('.tooltip')){
        // your parent element is being hovered over
    }
});

Though, as noted in the comments to your post, you can't hover over something with display: none as a style property.

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

Comments

0

Looking at your question, you are appending the span to the a. And I think you want something like this? I'm not quite sure because your question isn't super clear.

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.