PDA

View Full Version : Onclick Event Hander / Internet Explorer Compatibility



`Jeremy
02-22-2009, 08:16 PM
My first issue is that I need to be able to have my script change the onclick event in both Firefox and Internet Explorer. However, Internet Explorer has been a jerk about this issue. The only method that works in IE that I have found so far is document.getElementById('div'+id).onclick = function () { functionName(id); };. Unfortunately, this method does not work because I need to loop this command. In doing so, it leaves all of the onclicks' paramaters to be whatever id was last set to in the loop.

----

My second issue is hiding table rows. I'm looping this line: if (document.getElementById('queue'+id)) document.getElementById('queue'+id).className = 'noshow';. The CSS for noshow is .noshow {display:none;}. However, IE doesn't seem to want to hide the rows sometimes, but FF always does.

Any help for either issue is much appreciated.

A1ien51
02-23-2009, 04:31 AM
Well an easy solution is to use this


document.getElementById('div'+id).onclick = function () { functionName(this.id); };


If you check out my post here: http://www.coderanch.com/t/119917/HTML-JavaScript/Scope-Chain-Closures#594446 You can see solutions to make it work without using this [but using "this" is your best solution]

Eric

A1ien51
02-23-2009, 04:33 AM
For your second issue, have you used the Web Developer Toolbar and inspect the elements that are not being hidden and see if the class is being added?

Eric