Harry Pen Harry Pen - 7 months ago 13
HTML Question

How to show/hide content

I have a page where I would like two buttons which when one is clicked, displays hello, and when the other one is clicked would hide the "hello" message and then display "goodbye". I know this needs to be done in javascript but I am not good with javascript.

Answer

Check this snippet

<p id="msg"></p>

<button onclick="helloFunction()">Say Hello</button>
<button onclick="byeFunction()">Wave Goodbye</button>

<script>
function helloFunction() {
    document.getElementById("msg").innerHTML = "Hello";
}
  
  function byeFunction() {
    document.getElementById("msg").innerHTML = "Goodbye";
}

</script>