Javascript DOM HTML Node textContent Property set paragraph

Introduction

Change the textual content of a <p> element with id="myP":

document.getElementById("demo").textContent = "Paragraph changed!";

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo" onclick="myFunction()">Click me to change my textual content.</p>

<script>
function myFunction() {// w  w w . j a  va  2s.  c  o m
  document.getElementById("demo").textContent = "Paragraph changed!";
}
</script>

</body>
</html>



PreviousNext

Related