Jacob T Morris
Jacob T Morris

Reputation: 11

Changing paragraph content with button

Forgive my ignorance, because I'm pretty new to programing. I've been beating out my brains on this one. Can anyone tell me why this doesn't work? I know it will be something dumb:

        addText(){
            document.getElementById("demo").innerHTML = "New Content";
            }
  <!DOCTYPE html>
    <html>
        <head>
        <title>InnerHTML Example</title>
        </head>
        <body>
            <p id="demo">
                <Button onclick="addText()">Change</Button>
                Original Content
            </p>
           
        </body>
    </html>

Upvotes: 1

Views: 24

Answers (1)

Bret Lipscomb
Bret Lipscomb

Reputation: 499

You haven't declared addTest() as a function. Should be:

<script>
  function addTest() {
...
} 
</script>

function addText() {
  document.getElementById("demo").innerHTML = "New Content";
}
<!DOCTYPE html>
<html>

<head>
  <title>InnerHTML Example</title>
</head>

<body>
  <p id="demo">
    <Button onclick="addText()">Change</Button> Original Content
  </p>

</body>

</html>

Upvotes: 1

Related Questions