How To Change Text Onclick In HTML Using JavaScript

How to change the text on button click by using javascript. It is very simple with JavaScript display output “innerHTML” property that defines the HTML content between the tag. There are we can see in the code the HTML tag with the id that is defined in the JavaScript code.

HTML

<button type="button" onclick="document.getElementById('demoId').innerHTML = 'New content here'">Click On Me And Change Text</button>

<h1 id="demoId">Write here predefined content</h1>

CSS

button, h1 {
    margin: 50px auto;
    display: table;
    font-family: arial;
}
button {
    font-size: 18px;
    padding: 5px 10px;
    cursor: pointer;
}