So, using just javascript, I want to put all the text on a page into a string. There's probably some really easy way to do it, but I have no idea how.
Asked
Active
Viewed 413 times
1
-
Does this answer your question? [Convert an Entire HTML Page to a Single JavaScript String](https://stackoverflow.com/questions/22377564/convert-an-entire-html-page-to-a-single-javascript-string) – funnydman Nov 30 '19 at 19:04
-
@funnydman - this converts the HTML markup + the text, and not just the text, to a string. – Ori Drori Nov 30 '19 at 20:19
2 Answers
1
<!DOCTYPE html>
<html lang="en">
<head>
<title>Put Text on Me</title>
<script>
var sampleText = "Hi I am a text";
function writeTextOnPage(){
document.getElementById('putText').innerText = sampleText;
}
</script>
</head>
<body>
<p id='putText'></p>
<input type="button" onclick="writeTextOnPage()" value="Load Here">
</body>
</html>

Nitesh kumar
- 19
- 4
-
Above code is the combination HTML + js. JS code is written inside the script tag inside head tag. as your question is saying put text on the page, so we have created one variable called 'sampleText' and assigning some string value. In the same manner you also put all the string. One function is there which is adding text on button click. – Nitesh kumar Nov 30 '19 at 19:39