I have an HTML page with a heading and 2 Divs, I then have a javascript where I want the heading to change if the user selects one off the Divs.
https://jsfiddle.net/L27xqgfs/1/
var happyMood = getElementById("happy");
var sadMood = getElementById("sad");
happyMood.onclick = function () {
var mainHeading = getElementById("heading");
mainHeading.innerHTML = "You have selected ";
};
sadMood.onclick = function () {
var mainHeading = getElementById("heading");
mainHeading.innerHTML = "You have selected " + sadMood;
};
Please can someone advise where I've gone wrong?
Thanks in advance.
getElementById()is not a global function, trydocument.getElementById(). Start there.document.getElementByIdnotgetElementById!