Specify an element's own inner HTML - Javascript DOM

Javascript examples for DOM:Element innerHTML

Description

Specify an element's own inner HTML

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <!--Click the button to get id of the parent element --> 
      <button onclick="myFunction()">Try it</button> 
      <div id="parentDiv"> 
         <p id="demo"></p> 
      </div> 
      <script>
function myFunction() {/*www.j  a v  a2  s.c  om*/
var x = document.getElementById("demo").parentElement.id;
document.getElementById("demo").innerHTML = x;
 }
 
      </script>  
   </body>
</html>

Related Tutorials