In this tutorial we will learn how to Get all text from website page using JavaScript. For this we can use .innerText property.
Table of Contents
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.