Right now I'm using <body onload="function">
, which changes some text on the page based on which element is focused on. It works fine, but I need my site to run the function every time the focus changes (or, even better, every time any part of the page is clicked).
Currently the code looks like this:
<body onload="changeText()">
<script>
function changeText(){
function here;
}
</script>
<p>This is where text changes based on the function</p>
Thanks!
window.onclick = function () {
//do some stuff
document.body.style.backgroundColor = "red";
}
<p>text text text</p>
<button>it does not matters if you press me or any where else</button>
You can attach onclick event on document. jsfiddle
document.onclick = function(){
// your code
//alert("clicked");
}
If you want change on focus then use
window.onfocus = function(){
// your code
//alert("focus");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With