What I want : change text-color to red on text in a <h1>
tag with <id="headline">
Anyone that has an idea why the following code does not work, but further down in this question, that code work by moving onclick-event to inline code?
Does not work : following code written in external js-file
function changeColor(){
document.getElementById("headline").style.color = "red";
}
document.getElementById("headline").onclick = changeColor;
Works : Following code written in external js-file (function is the same):
function changeColor(){
document.getElementById("headline").style.color = "red";
}
…and this written in inline code:
<h1 id="headline" onclick="changeColor()">with inline code this text change color on click</h1>