Get all text from website page using JavaScript

In this tutorial we will learn how to Get all text from website page using JavaScript. For this we can use .innerText property.

HTML Code

HTML Code is given below, in this we a have dummy text and a button tag.

<!DOCTYPE html>
<html lang="">
<head>
	<meta charset="utf-8">
	<title>Get all text from website page using JavaScript</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
  <button onclick="getText()">Get Text</button>    
</body>
</html>

JavaScript Code

Take a look at the JavaScript code given below. On button click a function is executed which displays the text using alert function and javascript variable.

<script>
     function getText()
     {
     var text=document.body.innerText;
     alert(text);
     }
</script>

Demo

Video Tutorial

Watch video tutorial on How To Get all text from website page using JavaScript.

Change font-size using JavaScript Get Font Size of any Tag using JavaScript Change Position of HTML Element using JavaScript How to Change Image on Hover with JavaScript How to Disable Button by Class Name in JavaScript How To Change Image Size with JavaScript How to change Image opacity with JavaScript How to Change image src on click with JavaScript How to get the lang attribute value in JavaScript How to Get attribute Value using JavaScript How To Check if Attribute Exists or not with JavaScript How To Count number of links on Page with JavaScript How To Scroll Page to Bottom using JavaScript How To Detect Shift Key Press with JavaScript Change Text Color On Hover with JavaScript Hide and Show div using JavaScript Get Button text with JavaScript Get textarea value with JavaScript Get table row Height with JavaScript Auto Increase width of input field with JavaScript Set Textarea maxLength with JavaScript Set Textarea Value with JavaScript JavaScript Count list items JavaScript set input field value Count Button Clicks with JavaScript Scroll Page to the Top on Click with JavaScript