Am I trying to make something like a Javascript function as a parameter for another function? . But, unfortunately, I did not succeed. I did something wrong, but I do not know what. Pls help me!
There is a div element and function. What this function does: takes another function as a parameter and executes it when you click on a div element:
Update3: I tried to get the code to work with your examples under my original web project. But I have some problems with some parameters. I hope you can answer this question as quickly as others.
UPDATE4: Thanks Andy E! and to everyone who helped me! I really appreciate it!
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<div id='divElement'>Hello World!</div>
<script type="text/javascript">
function button(exefunction){
var date = '20101010';
document.getElementById('divElement').onclick = exefunction(date);
}
function testfunction(text){
document.getElementById('divElement').innerHTML = text;
}
button(testfunction);
</script>
</body>
</html>
source
share