I am currently working on a JavaScript code snippet where I am trying to change the headline text when it is clicked. The code I have written is:
var headline = document.getElementById("mainHeading");
headline.onClick = function() {
headline.innerHTML = "You clicked the headline.";
};
However, despite my efforts, clicking the headline does not trigger the desired action. It only works when I use onclick
instead of onClick
(without capital letter C).
To make matters worse, even after debugging with Chrome DevTools and Firebug, no syntax errors related to onClick
are being displayed.
If anyone has any tips or suggestions on how I can debug this issue effectively, please let me know.