Hello,
I found an old post similar to the question I was looking for but I still need answers. I have a website where all or most of the pages open up in the same page using ajax, kinda like an iframe. Yeah, well, I want the links in the menu to change to a different color when clicked and then stay that color until a new link is clicked... then once a new link is clicked the other link goes back to normal and the new link that was clicked changes to a different color and stays that way until another link is clicked and so on.
The script I'm using is the following which is in the <head> of my html:
<script type="text/javascript">
var lastClickedLink = null;
function rememberLink() {
if (lastClickedLink) {lastClickedLink.style.color = "green";lastClickedLink.style.backgroundColor = "white";lastClickedLink.style.fontStyle = "normal";}
lastClickedLink = this;
this.style.color = "white";
this.style.backgroundColor = "green";
this.style.fontStyle = "italic";
}
function makeMemory() {
for (var i=0; i<document.links.length; i++) {
var link = document.links[i];
if (link.addEventListener) {
link.addEventListener("click",rememberLink,false);
} else if (link.attachEvent) {
link.attachEvent("onclick",rememberLink);
} else {
link.onclick=rememberLink;
}
}
}
</script>
Then in the body I have:
<body onload="makeMemory()">
Now it works PERFECTLY in Firefox and even Safari, but, not in Internet Explorer. Does anyone know why this doesn't work in internet explorer?
OR does anyone know of a better code to make this work... I just want people to be able to tell what section they are in on my site, which is obvious, but, I like that effect of the link changing and staying until they go to another page...