Krij wrote:
<snip>
<script language="javascript">
The language attribute is deprecated and the type attribute required in
valid HTML 4, and its use makes the language attribute redundant:-
<script type="text/javascript">
<!--
This 'hide from older browsers' stuff with HTML comment-like structures
is no longer necessary and should not be used.
function chgColor(){
^
Add a formal parameter so that the event can be passed to this
function:-
function chgColor(ev){
var thistag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";
}
}
As the event will be passed to the function as an argument there is no
need to reference IE's global event object. Non-IE browsers use the -
target - property to indicate the originator of the event, so:-
var theTag = ev.srcElement || ev.target;
var theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}
- but the target may be a text node contained within an TD element so it
might be necessary to chain up the parent nodes until an element node is
encountered:-
function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.noteType != 1){
theTag = theTag.parentNode;
}
if(theTag){
theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}
}
Also, set the - backgroundColor - property of the element's - style -
object instead of using the deprecated - bgColor - property (unless you
are trying to actively support dinosaurs like Netscape 4).
<snip>
<body onmouseover="chgColor()" onmouseout="chgBack()"
Pass the event object(s) to your function from the event handing
functions:-
<body onmouseover="chgColor(event)" onmouseout="chgBack(event)"
<snip>
Richard Cornford skrev:
<snip>
Please do not top-post to comp.lang.javascript.
Richard.