0

Below a simple code:

HTML

<button type="button" onclick="message()" id="c" value="C">C</button>
<button type="button" onclick="clear()">Clear</button>
<span id="messageid"></span>

Javascript

<script>
function message() {
    document.getElementById("messageid").innerHTML = "Test";
}

function clear() {
    document.getElementById("messageid").innerHTML = "";
}
</script>

When I click clear button, the message output by button "C" is not clearing. I thought this is a fairly straight forward method to just call the innerHTML = "" to clear but apparently it didn't work. What am I missing here?

SunnyBoiz
  • 514
  • 1
  • 5
  • 14
  • 1
    Although `clear` is not a reserved word in javascript, it's an alias to document.clear(). Use another function name for your cleaning function, and it will work. – Elias Soares Feb 29 '20 at 15:49
  • Yeah tests that I was running works if you change the names of the functions, `message` and `clear` must be taken by other props on the window object – WillD Feb 29 '20 at 15:51
  • *facepalm* - I should really name my function properly for its role. Thanks for the clarification! – SunnyBoiz Feb 29 '20 at 15:58

0 Answers0