OK, this has gone on long enough. I really wish the folks at Microsoft would give less complicated examples of this stuff. Hopefully, now I will. Here is the script that I made up. The green comments should help explain things and can reamain in the code as long as the //'s remain as well. It goes in the head section of the page:
Code:
<html>
<head>
<title>index</title>
<script type="text/javascript">
function initCells(){
var switcher = function(){ // defines 'switcher' as:
// a test to see if the bgcolor is either navy or #000080 (navy's hex equivalent)
//and set the new color to silver (#c0c0c0) if it is or navy (#000080) if it isn't:
var newColor = /navy|#000080/.test(this.getAttribute('bgcolor', 0)) ? '#c0c0c0' : '#000080'
this.setAttribute('bgcolor', newColor, 0) // and set the bgcolor attribute to it
}
var cells = document.getElementsByTagName('td') // collects all td's on the page
for (var i_tem = 0; i_tem < cells.length; i_tem++) // for each one
cells[i_tem].onclick = switcher; // assigns the onclick event switcher()
}
onload = initCells; // gets the whole thing rolling after the browser has loaded
//the page so we can see where everything is before proceeding
</script>
</head>
<body>
Bookmarks