Hi,
I have created javascript Object which handle some onclick events.
When the event handler is called it refers some variables correctly and some variables incorrecly.
I cannot undastand what is happening here.
Please explain to me why it is working/not working........
My Code :
<HTML>
<HEAD><TITLE>Testing</TITLE>
<style>
.myClass{
background-color:blue;height:100px;text-align:center;cursor:hand;
}
</style>
<script LANGUAGE="JavaScript">
function Test(myDiv){
this.value1 = "This is value 01";
myDiv.onclick=func1;
var myVar = "This is my var";
function func1(){
alert(myDiv.id); //working fine
alert(myVar); //working fine
alert(this.value1); //not working
}
}
//****************************************************
function windlow_onload(){
new Test(div1)
}
</script>
</HEAD>
<BODY onload=windlow_onload()>
<div id=div1 class=myClass>Click Here</div>
</BODY>
</HTML>
I have created javascript Object which handle some onclick events.
When the event handler is called it refers some variables correctly and some variables incorrecly.
I cannot undastand what is happening here.
Please explain to me why it is working/not working........
My Code :
<HTML>
<HEAD><TITLE>Testing</TITLE>
<style>
.myClass{
background-color:blue;height:100px;text-align:center;cursor:hand;
}
</style>
<script LANGUAGE="JavaScript">
function Test(myDiv){
this.value1 = "This is value 01";
myDiv.onclick=func1;
var myVar = "This is my var";
function func1(){
alert(myDiv.id); //working fine
alert(myVar); //working fine
alert(this.value1); //not working
}
}
//****************************************************
function windlow_onload(){
new Test(div1)
}
</script>
</HEAD>
<BODY onload=windlow_onload()>
<div id=div1 class=myClass>Click Here</div>
</BODY>
</HTML>