1

I'm trying to get "event.target" to work and cannot. Check out the fiddle below. It works in Safari and Chrome, but not Firefox. I get nothing there.

mySpan.addEventListener('mouseup', function(){ textClick(); }, false)

function textClick (){
    outPutBox.innerHTML = event.target.textContent
}

Here's the full fiddle: https://jsfiddle.net/dmperkins74/ochvvn0o/

In the FF console, it says "event is not defined" but why is it working in the other browsers?

I'm quite a rookie, so please be gentle. Any help appreciated. Also, please don't throw any JQuery my way... I'm just not "there" yet.

Thanks, Dan P.

dmperkins74
  • 157
  • 3
  • 10
  • 1
    Possible duplicate of [ReferenceError: event is not defined error in Firefox](http://stackoverflow.com/questions/20522887/referenceerror-event-is-not-defined-error-in-firefox) – Sterling Archer Apr 12 '17 at 00:36

1 Answers1

0

Because event is not defined. It is passed from the event listener.

mySpan.addEventListener('mouseup', textClick, false)

function textClick (event) {
    outPutBox.innerHTML = event.target.textContent
}

or

mySpan.addEventListener('mouseup', function(e){ textClick(e); }, false)

function textClick (event) {
    outPutBox.innerHTML = event.target.textContent
}
epascarello
  • 204,599
  • 20
  • 195
  • 236