Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8946707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:34:58+00:00 2026-06-15T12:34:58+00:00

I am trying this code but i get: document.getElementsByName(…).style is undefined I have also

  • 0

I am trying this code but i get: document.getElementsByName(...).style is undefined

I have also a problem with the delegation, i think. Any help?

<html>
    <head>
    <style type="text/css">
    #toolTip {
        position:relative;
        width:200px;
        margin-top:-90px;
    }

    #toolTip p {

        padding:10px;
        background-color:#f9f9f9;
        border:solid 1px #a0c7ff;
        -moz-border-radius:5px;-ie-border-radius:5px;-webkit-border-radius:5px;-o-border-radius:5px;border-radius:5px;
    }

    #tailShadow {
        position:absolute;
        bottom:-8px;
        left:28px;
        width:0;height:0;
        border:solid 2px #fff;
        box-shadow:0 0 10px 1px #555;
    }

    #tail1 {
        position:absolute;
        bottom:-20px;
        left:20px;
        width:0;height:0;
        border-color:#a0c7ff transparent transparent transparent;
        border-width:10px;
        border-style:solid;
    }

    #tail2 {
        position:absolute;
        bottom:-18px;
        left:20px;
        width:0;height:0;
        border-color:#f9f9f9 transparent transparent transparent;
        border-width:10px;
        border-style:solid;
    }
    </style>
    <script type='text/javascript'>
    function load () {
            var elements = document.getElementsByName('toolTip');
            for(var i=0; i<elements.length; i++) {
                document.getElementsByName(elements[i]).style.visibility = 'hidden';
            }
        }
    </script>

    </head>



    <body onload="load()">
    <br><br><br><br><br><br><br><br><br><br><br><br>
    <a class="hd" 
    onMouseOver="document.getElementsByName('toolTip')[0].style.visibility = 'visible'"
    onmouseout ="document.getElementsByName('toolTip')[0].style.visibility = 'hidden'">aqui</a>
    <div id="toolTip" name="toolTip">
        <p>i can haz css tooltip</p>
        <div id="tailShadow"></div>
        <div id="tail1"></div>
        <div id="tail2"></div>
    </div>

    <br><br><br>
    <a class="hd" 
    onMouseOver="document.getElementsByName('toolTip')[0].style.visibility = 'visible'"
    onmouseout ="document.getElementsByName('toolTip')[0].style.visibility = 'hidden'">aqui</a>
    <div id="toolTip" name="toolTip">
        <p>i can haz css tooltip</p>
        <div id="tailShadow"></div>
        <div id="tail1"></div>
        <div id="tail2"></div>
    </div>

    </body>
    </html>

demo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:34:59+00:00Added an answer on June 15, 2026 at 12:34 pm

    Try changing the id toolTip to a class:

    <div class="toolTip">...</div>
    

    And change your JS to use the display style-thing, rather than visibility, nd the onmouseover’s are best dealt with using JS event delegation:

    function load()
    {
        var i, tooltips = document.getElementsByClassName('toolTip'),
        mouseOver = function(e)
        {//handler for mouseover
            e = e || window.event;
            var i, target = e.target || e.srcElement,
            targetToolTip = target.nextElementSibling || nextSibling;//gets the next element in DOM (ie the tooltip)
            //check if mouse is over a relevant element:
            if (target.tagName.toLowerCase() !== 'a' || !target.className.match(/\bhd\b/))
            {//nope? stop here, then
                return e;
            }
            targetToolTip.style.display = 'block';//make visible
            for (i=0;i<tooltips.length;i++)
            {//closures are neat --> you have a reference to all tooltip elements from load scope
                if (tooltips[i] !== targetToolTip)
                {//not the one you need to see
                    tooltips[i].style.display = 'none';
                }
            }
        };
        for (i=0;i<tooltips.length;i++)
        {
            tooltips[i].style.display = 'none';
        }
        //add listener:
        if (document.body.addEventListener)
        {//IE > 9, chrome, safari, FF...
            document.body.addEventListener('mouseover',mouseOver,false);
        }
        else
        {//IE8
            document.body.attachEvent('onmouseover',mouseOver);
        }
    }
    

    Google JavaScript event delegation and closures if this code isn’t clear, but that’s just how I would tackle this kind of thing. IMO, it’s fairly efficient (you could use the closure scope to keep track of the tooltip that’s currently visible and not loop through all of them, too, that would be even better:

    function load()
    {
        var i, tooltips = document.getElementsByClassName('toolTip'),
        currentToolTip,//<-- reference currently visible
        mouseOver = function(e)
        {
            e = e || window.event;
            var i, target = e.target || e.srcElement,
            targetToolTip = target.nextElementSibling || nextSibling;
    
            if (target.tagName.toLowerCase() !== 'a' || !target.className.match(/\bhd\b/) || targetToolTip === currentToolTip)
            {//add check for currently visible TT, if so, no further action required
                return e;
            }
            if (currentToolTip !== undefined)
            {
                currentToolTip.style.display = 'none';//hide currently visible
            }
            targetToolTip.style.display = 'block';//make new visible
            currentToolTip = targetToolTip;//keep reference for next event
        };
        for (i=0;i<tooltips.length;i++)
        {
            tooltips[i].style.display = 'none';
        }
        if (document.body.addEventListener)
        {
            document.body.addEventListener('mouseover',mouseOver,false);
        }
        else
        {
            document.body.attachEvent('onmouseover',mouseOver);
        }
    }
    

    And you’re there.

    Edit:
    To hide the tooltip on mouseout, you can either add a second listener directly:

    function load()
    {
        var i, tooltips = document.getElementsByClassName('toolTip'),
        currentToolTip,//<-- reference currently visible
        mouseOver = function(e)
        {
            e = e || window.event;
            var i, target = e.target || e.srcElement,
            targetToolTip = target.nextElementSibling || nextSibling;
    
            if (target.tagName.toLowerCase() !== 'a' || !target.className.match(/\bhd\b/) || targetToolTip === currentToolTip)
            {//add check for currently visible TT, if so, no further action required
                return e;
            }
            if (currentToolTip !== undefined)
            {
                currentToolTip.style.display = 'none';//hide currently visible
            }
            targetToolTip.style.display = 'block';//make new visible
            currentToolTip = targetToolTip;//keep reference for next event
        },
        mouseOut = function(e)
        {
            e = e || window.event;
            var movedTo = document.elementFromPoint(e.clientX,e.clientY);//check where the cursor is NOW
            if (movedTo === curentToolTip || currentToolTip === undefined)
            {//if cursor moved to tooltip, don't hide it, if nothing is visible, stop
                return e;
            }
            currentTooltip.style.display = 'none';
            currentTooltip = undefined;//no currentToolTip anymore
        };
        for (i=0;i<tooltips.length;i++)
        {
            tooltips[i].style.display = 'none';
        }
        if (document.body.addEventListener)
        {
            document.body.addEventListener('mouseover',mouseOver,false);
            document.body.addEventListener('mouseout',mouseOut,false);
        }
        else
        {
            document.body.attachEvent('onmouseover',mouseOver);
            document.body.attachEvent('onmouseout',mouseOut);
        }
    }
    

    Note, this is completely untested. I’m not entirely sure if IE < 9 supports elementFromPoint (gets the DOM element that is rendered at certain coordinates), or even if the IE event object has the clientX and clientY properties, but I figure a quick google will tell you more, including how to get the coordinates and the element that is to be found under the cursor in old, crummy, ghastly IE8, but this should help you on your way. Of course, if you don’t want the contents of the tooltip to be selectable, just change the mouseOut function to:

    mouseOut = function(e)
    {
        e = e || window.event;
        var target = e.target || e.srcElement;
        if (currentToolTip)
        {
            currentToolTip.style.diplay = 'none';
            currentToolTip = undefined;
        }
    };
    

    No need to check if the mouseout was on the correct element, just check if there is a current tooltip, and hide it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to play video from youtube using this code but I get this
Forgive me for this unbeautiful code, but I'm trying to get it to work
I have this code, but I get the error described in the title: The
I'm trying to get the direction property for the element. I have this code:
i have this code function, im trying to get an html and appendchild a
I've been trying to get this code working in Google Chrome but I can't
I have been trying to get this code to work for a while now
Trying to get this code to work but the error I am getting in
I'm trying to run this code but this error appear: Uncaught TypeError: string is
I'm trying this code to access a property but it gives me an error:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.