0

Hi I have something similar. when I click MESSAGE1 button the the text Hello World appears and the button disappears. When the button is clicked how do I retain the button alongside the text?

<button onclick="document.write('<?php echo 'Hello World'; ?>');">MESSAGE 1</button>
John English
  • 121
  • 1
  • 5
  • 12

1 Answers1

1

Instead of using document.write, you can create a html element place holder and then set its content

<button onclick="document.getElementById('message').innerHTML = '<?php echo 'Hello World'; ?>';">MESSAGE 1</button>
<span id="message"></span>

The button is remove because, from this doc

document.write is recklessly dependent on timing. If document.write is called before the onload event, it appends or inserts text into the page. If it is called after onload, it completely replaces the page, destroying what came before.

Community
  • 1
  • 1
Arun P Johny
  • 365,836
  • 60
  • 503
  • 504