PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 15, 2022

[FIXED] Why is the element replaced

 October 15, 2022     dom, javascript     No comments   

Issue

I'm curious as to why the element is replaced, rather than added at the end of the div...?

<!DOCTYPE html>
  <html>
    <body>

    <h1>JavaScript in Body</h1>

    <div id="demo">
    <h1>A paragraph will appear below</h1>
    </div>

    <button type="button" onclick='document.getElementById("demo").innerHTML = "<p>My First JavaScript</p>"'>Insert a paragraph</button>


  </body>
</html> 

Solution

You can replace = with += to append innerHTML instead of replacing it.



Answered By - Valtteri Laitinen
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,242,972

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing