I am currently working on writing a code that will allow me to make any part of the screen clickable. When a user clicks on the screen, a message saying "click!" should be displayed. So far, this is the code I have:
HTML:
<html>
<head>
<title>Handling Events Anywhere</title>
<script type="text/javascript" src="anywhere.js"></script>
<link type="text/css" rel="stylesheet" href="anywhere.css" />
</head>
<body id="body" onload="init();">
<div id="message"> Click! </div>
</body></html>
JavaScript:
var element;
function init(){
element = document.getElementById("message");
document.getElementById("message").style.visibility = "hidden";
element.onmousedown = displayMessage(element);
element.onmouseup = hideMessage;
}
function displayMessage(element) {
element.style.visibility = "visible";
}
function hideMessage() {
element.style.visibility = "hidden";
}
CSS:
body {
}
div#message{
}
So far, my attempts to show and hide the message when clicked have not been successful. I apologize for any language errors in my explanation. English is not my first language. If anyone could assist me with this, it would be greatly appreciated. Thank you.