I’m trying to remove a script entirely to an external .js file and replace the onClick event with addEventListener in the external file. I can’t get this to work:
http://jsfiddle.net/kjmatthews/DE26x/
My function is a little more complex, but this is essentially copied from http://jsfiddle.net/madBYK/UumUP/, linked from the developer.mozilla.org page on element.addEventListener.
Adding onclick="return hidePurchased();" to the <input> tag does work, so the problem is not with the hidePurchased() function.
Any help would be much appreciated!
getElementsByNamereturns aNodeList, which doesn’t haveaddEventListenermethod, so you need to actually select the guy you are intending to bind the click listener to, by dereferencing the resultTry:
Working example:
http://jsfiddle.net/DE26x/9/