<div id="myElement2"></div>
<script>
window.onload = function() {
document.getElementById("myElement1").onclick = function() {
for (i = 0; i < 2; i++) {
document.getElementById("myElement2").onmouseover = func;
function func() {alert("hello"); } } } }
</script>
In chrome and IE, when myElement1 is clicked, func is perfectly tied to myElement2. However, in firefox, when you click myElement1, an error message appears indicating that func is undefined.
I should note that if you make an anonymous function instead of func, then it works in all three browsers.
My question is, how does firefox handle scope in this regard differently for IE and chrome?
Will.
source
share