Penguin Penguin - 20 days ago 7
HTML Question

What does each of the following codes in a HTML file mean?

<button type="button"
onclick="document.getElementById('msg').innerHTML = 'Gone!'">
Click Me!</button> <button type="button"
onclick="document.getElementById('msg').innerHTML = 'Back again!'">
Bring me back!</button>


Can someone explain what each line means?

Answer

On click of buttons it will search for the element with id="msg" and set its inner HTML i.e. content of the element.

https://jsfiddle.net/night11/qs3sL6qt/1/

<p id="msg">My first paragraph</p>
<button type="button"
onclick="document.getElementById('msg').innerHTML = 'Gone!'"> 
Click Me!</button> <button type="button"
onclick="document.getElementById('msg').innerHTML = 'Back again!'">
Bring me back!</button>