0
Q:

echo value in div using javascript

element.innerHTML = element.innerHTML + "additional HTML code"
0
element.innerHTML += "additional HTML code"
0
<!DOCTYPE html> 
<html> 
  
<head> 
    <title>How to Append HTML Code to a Div using Javascript</title> 
    <style> 
        body { 
            text-align: center; 
              
            padding: 5%; 
        } 
        h1{ 
            color:green; 
        } 
    </style> 
</head> 
  
<body> 
    <div id="add_to_me"> 
        <h1>GeeksforGeeks</h1> 
        <p>This is the text which has already been typed into the div</p> 
    </div> 
  
    <button onclick="addCode()">Add Stuff</button> 
    <script> 
        function addCode() { 
            document.getElementById("add_to_me").innerHTML +=  
              "<h3>This is the text which has been inserted by JS</h3>"; 
        } 
    </script> 
</body> 
  
</html> 
0

New to Communities?

Join the community