D
De_Dood
Hello all,
I have a problem with the code below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript">
function test() {
this.helloDiv = document.createElement("div");
this.show = function() {
this.helloDiv.style.backgroundColor = "red";
this.helloDiv.style.borderColor = "black";
this.helloDiv.style.borderStyle = "solid";
this.helloDiv.style.borderWidth = "1px";
this.helloDiv.innerHTML = "DIV";
date = new Date()
this.creationTime = date.getTime()
this.helloDiv.onclick = function clicked () {
alert(this.creationTime);
}
document.body.appendChild(this.helloDiv);
}
}
function init() {
var div1 = new test();
div1.show();
var div2 = new test();
div2.show();
}
</script>
</head>
<body onload="init()">
</body>
</html>
I'd like to access my "creationTime" variable defined in my "show"
function from within my onclick-event defined function.
I've come so far to discover that the "this" in my onclick-event
function points to the div element and not to one of the 'test'
objects. But I can't find a solution on how to solve my problem.
Can someone help me with this.
Thanks in advance!
Kind regards,
Tim De Graeve
I have a problem with the code below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript">
function test() {
this.helloDiv = document.createElement("div");
this.show = function() {
this.helloDiv.style.backgroundColor = "red";
this.helloDiv.style.borderColor = "black";
this.helloDiv.style.borderStyle = "solid";
this.helloDiv.style.borderWidth = "1px";
this.helloDiv.innerHTML = "DIV";
date = new Date()
this.creationTime = date.getTime()
this.helloDiv.onclick = function clicked () {
alert(this.creationTime);
}
document.body.appendChild(this.helloDiv);
}
}
function init() {
var div1 = new test();
div1.show();
var div2 = new test();
div2.show();
}
</script>
</head>
<body onload="init()">
</body>
</html>
I'd like to access my "creationTime" variable defined in my "show"
function from within my onclick-event defined function.
I've come so far to discover that the "this" in my onclick-event
function points to the div element and not to one of the 'test'
objects. But I can't find a solution on how to solve my problem.
Can someone help me with this.
Thanks in advance!
Kind regards,
Tim De Graeve