1

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

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.