I am having trouble getting "this" to work in all versions of IE (it's fine in Firefox, opera, konqueror, etc). What I would like to do is add an event listener to an element to change its border on mouseover and mouseout. I don't want to use CSS to do this (long story).
The problem is that "this" does not work at all in IE for me. I tried to do a try/catch statement and use "window.event.s rcElement", but this causes all of the child elements to fire the function as well, which is obviously not desireable (I don't want the children to have borders).
So I have 2 questions:
1. Do I have a syntax error that is preventing "this" from working in IE or does IE just not support it?
2. How do I get the function to fire on the parent element only and not the children?
This is what my html looks like:
[HTML]<div class="borderCh anges">
<img src="path/to/img" alt="img description" />
<a href="link">Lin k Text</a>
<div>Some more Text</div>
</div>[/HTML]
This is the javascript that I am attaching to the div:
Expand|Select|Wrap|Line Numbers
- function linkHover (){
- try {this.style.border = "2px solid green";}
- catch (err){window.event.srcElement.style.border = "2px solid green";}
- try {this.style.padding = "4px";}
- catch (err){window.event.srcElement.style.padding = "4px";}
- }
- function linkOut (){
- try {x=this.style.border = "1px solid black";}
- catch (err){event.srcElement.style.border = "1px solid black";}
- try {x=this.style.padding = "5px";}
- catch (err){event.srcElement.style.padding = "5px";}
- }