Reputation: 1170
code below works fine if I run it on google chrome browser but it doesn't on firefox
the event object is undefined in firefox .So how can I get a reference to event object in this case
<html>
<body>
<p>Click the button to display the date.</p>
<button onclick="displayDate()">The time is?</button>
<script>
function displayDate(e) {
if (!e) var e = window.event;
alert(e.target.innerText);
document.getElementById("demo").innerHTML = Date();
}
</script>
<p id="demo"></p>
</body>
</html>
thank for your help
Upvotes: 1
Views: 58
Reputation: 239
For Firefox, you have to pass the event to the function:
<button onclick="displayDate(event)">The time is?</button>
<script>
function displayDate(e) {
document.getElementById("demo").innerHTML = Date();
}
</script>
http://jsfiddle.net/k6cge4a0/1/
Upvotes: 1