0
<button id="btnSubmit" value="Submit">Submit</button>

External script file

var btn = document.querySelector('#btnSubmit');
btn.addListener('click', function(){
    alert('Loading...');
}, false);

I get

null is not an object evaluating btn.addEventListener

It is reading before the button is rendered.

It however works fine in jsfiddle. http://jsfiddle.net/7enwttgq/

user544079
  • 16,109
  • 42
  • 115
  • 171
  • Jsfiddle may be giving you a false positive because of the nature of how it works. Where is your script in relation to your – musicfuel Jan 28 '15 at 22:32
  • In the fiddle it works because the code runs in a `load` event handler. If in "Frameworks & Extensions" you choose "No wrap - in ", it won't work. – Oriol Jan 28 '15 at 22:32

0 Answers0