The answer to this Question will probably be really easy and obvious. I want to asign some values on a Buttonclick via JavaScript. I get the following Error: "Uncaught TypeError: Cannot set property 'onmousedown' of null". I searched for maby 1 hour but didn't find anything.
The biggest problem is; THE EXACT SAME CODE WORKS ON A FIDDLE!!! https://jsfiddle.net/qnbdt2o9/
Am I missing something? I know, I could use JQuery, bit I want to do it in vanilla JS.
Does Someone see a Error in my Code?
var btn = document.getElementById("btn");
btn.onmousedown = function(){
var startFitness = document.getElementById('startFitness').value;
var maxFitness = document.getElementById('maxFitness').value;
var maxSpeed = document.getElementById('maxSpeed').value;
var minSpeed = document.getElementById('minSpeed').value;
var agility = document.getElementById('agility').value;
cosAtt = [startFitness, maxFitness, maxSpeed, minSpeed, agility];
console.log(cosAtt);
}
<h4>Start Fitness <input type="text" id="startFitness"></h4>
<h4>Max Fitness <input type="text" id="maxFitness"></h4>
<h4>Max Speed <input type="text" id="maxSpeed"></h4>
<h4>Min Speed <input type="text" id="minSpeed"></h4>
<h4>Agility <input type="text" id="agility"></h4>
<button id="btn">+ Add</button>
EDIT:
I forgott to add a important Codeline to the question