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 330135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:39:11+00:00 2026-05-12T09:39:11+00:00

Good Sunday morning! After fiddling around with some JavaScript this weekend, I finally wrote

  • 0

Good Sunday morning!

After fiddling around with some JavaScript this weekend, I finally wrote my first script. It is a Tooltip generator. It works great in FF 3 + 3.5, IE 6 + 7, Safari 4, Chrome 2 + 3, and Opera 9 + 10.

Before putting my new code into production, I thought I’d ask if you see any glaring problems — or maybe it’s perfect as-is? (Lol)

JSLint.com reports:

Error:

Problem at line 10 character 15: 'e' is already defined.

    var e = window.event;

Implied global: window 10, document 19,20,22,24,33,35,41,43,49,55

Here is my code (apologies in advance if you don’t like my code style):

function getmouseposition( e )
{
    var offx = 22;
    var offy = 14;
    var posx = 0;
    var posy = 0;

    if ( !e )
    {
        var e = window.event;
    }
    if ( e.pageX || e.pageY )
    {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if ( e.clientX || e.clientY )
    {
        posx = e.clientX
               + document.body.scrollLeft
               + document.documentElement.scrollLeft;
        posy = e.clientY
               + document.body.scrollTop
               + document.documentElement.scrollTop;
    }
    if ( document.getElementById )
    {
        var tooltip = document.getElementById( 'tooltip' );

        tooltip.style.left = ( posx + offx ) + 'px';
        tooltip.style.top = ( posy + offy ) + 'px';
    }
}

function tooltip_on( text )
{
    if( !document.getElementById( 'tooltip' ) )
    {
        var span = document.createElement( 'span' );

        span.id = 'tooltip';
        span.style.display = 'none';
        span.innerHTML = ' ';

        document.body.appendChild( span );
    }
    var tooltip = document.getElementById( 'tooltip' );

    tooltip.innerHTML = text;
    tooltip.style.display = 'block';
    tooltip.style.position = 'absolute';

    document.onmouseover = getmouseposition;
    // document.onmousemove = getmouseposition;
}

function tooltip_off()
{
    document.getElementById( 'tooltip' ).style.display = 'none';
}

EDIT:

I’m also wondering, what does this line say (in layman’s terms ) in the getmouseposition function:

if ( document.getElementById )
  • 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-05-12T09:39:12+00:00Added an answer on May 12, 2026 at 9:39 am

    That jslint error means that the variable e is already defined within the scope of the getmouseposition function by virtue of being an argument to said function. There is no need to redeclare it, so just remove the var from that line.

    Second, explicitly accessing properties of the window and document objects is pretty standard. I wouldn’t change that part of your code. Not sure why jslint even mentions those lines.

    Very picky style police will complain about spaces just within parentheses:

    // Most do this:
    function myFunction(param){
       // Statement 1
       // Statement 2
       // Statement 3
    }
    
    // Not this
    function myFunction( param )
    {
       // Statement 1
       // Statement 2
       // Statement 3
    }
    

    And very very picky style dorks will tell you to use a single var declaration at the top of your function:

    // Do this
    function getmouseposition(e){
        var offx = 22,
            offy = 14,
            posx = 0,
            posy = 0;
    
    
    // Not this
    function getmouseposition(e)
    {
        var offx = 22;
        var offy = 14; 
        var posx = 0;
        var posy = 0;
    

    Lastly, most style-conscious javascript programmers will use camel case for functions, so getMousePosition instead of getmouseposition

    My opinion is that, besides removing the var declaration as I suggested at the top, your code is quite readable and decent style, as long as you stick to the format consistently.

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

Sidebar

Ask A Question

Stats

  • Questions 260k
  • Answers 261k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Look carefully at the 6th frame of the animation on… May 13, 2026 at 11:30 am
  • Editorial Team
    Editorial Team added an answer semantic, ropemacs and pysmell are all emacs extensions. Do you… May 13, 2026 at 11:30 am
  • Editorial Team
    Editorial Team added an answer Without knowing much about your requirements, I'd suggest using a… May 13, 2026 at 11:30 am

Related Questions

Let's say at your job your boss says, That system over there, which has
I've been wondering why would I use Exceptions in my PHP. Let's take a
I am working on a system related to tv recordings. I am parsing the
So I have a problem. Or rather my friend has a problem, since I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.