Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How I can make window.event.srcElement work under Firefox

Status
Not open for further replies.

Ducu

Programmer
Oct 2, 2003
30
RO
Hi,

I am having trouble with a specific Firefox problem; using Javascript I am changing the color of a span tag on the mousover event. It works fine under IE, not working under FF at all. Il will work probably with getElementById() but I don't want to put id's every where.

The code it looks like this.Please forget the text in the web page is not relevant :)):

<html>
<head>
<style>
.txt2 {
font-size:9pt;

color: #000099;
font-family: Arial, Helvetica, sans-serif;
}
div.lay {background-color: #99CC99; color:#000099; border: 1px solid #333333; }
div.lay4 { background-color:#888888;
font-size:11pt;
font-variant: small-caps;
color: #99FF99;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}

</style>
<script type="text/javascript">
function schmb()
{
var ref;
ref=(window.event.target) ? window.event.target : window.event.srcElement;
ref.style.color="#666699";
return;
}

function revin()
{
var ref;
ref=(window.event.target) ? window.event.target : window.event.srcElement;
ref.style.color="#000099";
return;
}
</script>
</head>
<body>
<table width="175"><tr><td>
<div class="lay" align="center">
<div class="lay4">Links</div>
<a href="#" style="text-decoration:none;" ><span class="txt2" onMouseOver="schmb();" onMouseOut="revin();" > Pagina principala </span></a><br>
<a href="#" style="text-decoration:none;"><span class="txt2" onMouseOver="schmb();" onMouseOut="revin();"> Comunicate & Evenimente </span></a><br>
<a href="#" style="text-decoration:none;"><span class="txt2" onmouseover="schmb();" onmouseout="revin();"> Hotarari ale CJSM </span></a>
</div>
</td></table>
</body
</html>
 
Why not simply pass "this" through to the event handler:

Code:
onmouseover="schmb(this);" onmouseout="revin(this);"

Then modify your functions to take a parameter:

Code:
function schmb(obj) {
	obj.style.color = '#666699';
}

function revin(obj) {
	obj.style.color = '#000099';
}

I've not tested this, but I'm pretty sure it works cross-browser.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thank you ! It works fine ! I was complicating the things way too much !

Ducu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top