0 points

innerHTML - How to get or change the inside of a HTML element


Sun Jan 26 2020 20:43:45 GMT+0000 (UTC)

Posted by @_right_away_ #html #javascript #dom #dommanipulation

	<div id="target">
    	<p>This is some text</p>


      var divElement = document.getElementById("target").innerHTML;

      var heading = '<h1>Example text</h1>';
      document.getElementById("target").innerHTML = heading;

        document.getElementById("target").innerHTML = '';

content_copy Copy

Line 10: GET contents of div element and store in variable divElement The value of the variable divElement is: <p>This is some text</p> Lines 13-14: The inside of the div element with id= "target" is replaced with a <h1> tag declared as variable heading. Line 17: The inside of the div element is set to empty. It now contains nothing.