Add onmouseover function to all hyperlinks

Hi,

I am having great difficulty adding onmouseover events programatically to all links.
I simply want to have all links display their title attribute in the window.status(bar) when you mouseover.

Please see the attached code - the basic framework for the code is their, I JUST CANT ADD THE ONMOUSOVER EVENT.
//----------------------------------------------------------
// Attaches a function to the event of specified object
// @param obj the object the event is being attached to
// @param eventType the event type (e.g. "load") - do not include "on" as in "onload"!
// @param fn the function to attach
//----------------------------------------------------------
function addEvent(obj, eventType, fn)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(eventType, fn, true);
		return true;
	}
	else if (obj.attachEvent)
	{
		var r = obj.attachEvent("on" + eventType, fn);
		return r;
	}
	else
	{
		return false;
	}
}
//--------------------------------------------------------------------
// Make status bar display all titles on links.
//--------------------------------------------------------------------
addEvent(window, "load", function(){
 
    for(var i=0;i<document.links.length;i++)
    {
        if (document.links[i].title && document.links[i].title != null && document.links[i].title != "")
        {
            addEvent(document.links[i], "mouseover", function(){ 
                alert(this.title); //THIS IS NOT WORKING - WHY??? IT SHOULD ALERT THE LINK TITLE ATTRIBUTE.
                //window.status=this.title; 
                //return true; 
           });
        }   
    }
});

Open in new window

smaccaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Here you go:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript"><!--
//----------------------------------------------------------
// Attaches a function to the event of specified object
// @param obj the object the event is being attached to
// @param eventType the event type (e.g. "load") - do not include "on" as in "onload"!
// @param fn the function to attach
//----------------------------------------------------------
function addEvent(obj, eventType, fn)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(eventType, fn, true);
		return true;
	}
	else if (obj.attachEvent)
	{
		var r = obj.attachEvent("on" + eventType, fn);
		return r;
	}
	else
	{
		return false;
	}
}
//--------------------------------------------------------------------
// Make status bar display all titles on links.
//--------------------------------------------------------------------
addEvent(window, "load", function(){
 
    for(var i=0,limit=document.links.length ;i<limit;i++)
    {
        if (document.links[i].title && document.links[i].title != null && document.links[i].title != "")
        {  var t= document.links[i].title;
            addEvent(document.links[i], "mouseover", setStat(t) );
        }   
    }
});
 
function setStat(s)
{
	return function(){window.status=s; return true;}
}
//--></script>
</head>
<body>
<ul>
	<li><a href="#" title="alpha">Alpha</a></li>
	<li><a href="#" title="beta">Beta</a></li>
</ul>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.