I need to dynamically attach a function to a div and pass also the event.
It is working in Chrome / IE, but not FireFox.
I am getting the following error in FireFox console: ReferenceError: event is not defined
How can this be solved?
CodePen: https://codepen.io/dsomekh/pen/YrKmaR
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
.example{
cursor:pointer;
border:1px solid black;
text-align:center;
}
</style>
<script>
window.onload = function() {
var div = $( ".example" );
div.click(function() {Test(event);});
}
function Test (event)
{
alert(event);
}
</script>
<html>
<div class="example">When clicking on this div, you should get an alert with the event details. This does not work in FireFox.</div>
</html>