0

New to Javascript. Tried text type javascript also. Not worked. I doing this piece of code in notepad++ using html as extension and implementing on mozilla.

<html>

<head></head>

<body>
  <h1>JavaScript in Body</h1>
  <p id="demo">A Paragraph.</p>
  <button type="button" onclick="myFunction()">Try it</button>
  <script>
    function myFunction() {
      document.getElementById("demo").innerHtml = "Paragraph changed";
    }
  </script>
</body>

</html>

1
  • .innerHTML, "HTML" is all caps. Commented Apr 20, 2017 at 17:12

3 Answers 3

1

myFunction is trying to call innerHtml but it should be innerHTML (HTML is capitalised).

function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed"; }

Sign up to request clarification or add additional context in comments.

Comments

0

You need to capitalize the .innerHTML: https://jsfiddle.net/1e091yo2/

function myFunction(){
    document.getElementById("demo").innerHTML = 'See, I told you.'
    }

Comments

0

Check this working code.

   

function myFunction() {
        document.getElementById("demo").innerHTML= "Paragraph changed";
    }
   

<h1>JavaScript in Body</h1>
    <p id="demo">A Paragraph.</p>
    <button type="button" onclick="myFunction()">Try it</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.