Function to find all HTML Element Tag from HTML Document which have text
render()
{
let partial: any;
let elements = document.body.getElementsByTagName("*");
var scripts = document.body.getElementsByTagName("script");
for (var i = 0; i < elements.length; i++) {
var flag = true;
for (var j = 0; j < scripts.length; j++) {
if (elements[i] == scripts[j]) {
flag = false;
break;
}
}
if (flag) {
var str = i == 0 ? elements[i].outerHTML : elements[i].innerHTML;
if (str) {
let currElement: Element = elements[i];
if (this.readText(str) != "") {
currElement.classList.add(".parenteditable");
console.log(this.readText(str));
}
}
}
}
return (<div></div>);
}
readText = function (str) {
var a = document.createElement('div');
a.innerHTML = str;
var htmlText = "";
for (var c = a.childNodes, i = c.length; i--;) {
if (c[i].nodeType == 3 && c[i].textContent)
htmlText = htmlText + c[i].textContent;
}
return htmlText.trim();
}
render()
{
let partial: any;
let elements = document.body.getElementsByTagName("*");
var scripts = document.body.getElementsByTagName("script");
for (var i = 0; i < elements.length; i++) {
var flag = true;
for (var j = 0; j < scripts.length; j++) {
if (elements[i] == scripts[j]) {
flag = false;
break;
}
}
if (flag) {
var str = i == 0 ? elements[i].outerHTML : elements[i].innerHTML;
if (str) {
let currElement: Element = elements[i];
if (this.readText(str) != "") {
currElement.classList.add(".parenteditable");
console.log(this.readText(str));
}
}
}
}
return (<div></div>);
}
readText = function (str) {
var a = document.createElement('div');
a.innerHTML = str;
var htmlText = "";
for (var c = a.childNodes, i = c.length; i--;) {
if (c[i].nodeType == 3 && c[i].textContent)
htmlText = htmlText + c[i].textContent;
}
return htmlText.trim();
}