Assuming you only want children of body
element...
Example HTML
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> Example</title>
</head>
<body>
a <div>b<span>c</span></div>
</body></html>
JavaScript
var body = document.body;
var textContent = body.textContent || body.innerText;
console.log(textContent); // a bc
You need to check for textContent
because our good friend IE uses innerText
instead.
It is much easier if you have a library such as jQuery, i.e. $('body').text()
.
Also, it can be achieved on the server side, such as strip_tags()
in PHP. However, if you only wanted the body
element, you'd need to drill down to it using a DOM parser such as DOMDocument.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…