Saturday, December 19, 2009

ie vs ff on javascript

We all know how painful it is to deal with the standard differences when it comes to javascript programming across IE and Firefox. There can be many to be listed, but I’m going to list them out as a series of posts over time. These are going to be my findings, so correct any mistakes i may have.

Access DOM Object in an attached event
let’s say you have a link on the page that you want to attach an onclick event to
and assume addEvent is a method created to support both IE and FF

Under Firefox, if you want to access the linkObj, you can simply use “this”
linkObj.addEvent(”click”, function(){
Under IE, you can’t use “this” because “this” will referrer to the document object
instead, you have to use srcElement, and pass in e as an argument
linkObj.addEvent(”click”, function(e){
var thisObj=e.srcElement;