-1

In a SharePoint scripting web part How do I get to the actual text (All systems...) from this in JavaScript (It was read in from a list using REST) ?

"<div class="ExternalClass4DAE47C7DFE0401F910DF3D93A5690D3">
<span id="ms-rterangepaste-start"></span>
<span style="background-color&#58;transparent;color&#58;rgb(68, 68, 68);font-size&#58;24px;font-style&#58;normal;font-variant&#58;normal;font-weight&#58;400;letter-spacing&#58;normal;orphans&#58;2;text-align&#58;left;text-decoration&#58;none;text-indent&#58;0px;text-transform&#58;none;white-space&#58;normal;word-spacing&#58;0px;">
    All systems operating normally....... 
</span>
 <span> id="ms-rterangecursor-start"></span>
 <span> id="ms-rterangecursor-end"></span>
 <span> id="ms-rterangepaste-end"></span> <br></div>"

1 Answer 1

0

There are couple of easiest way to extract only text:

Using script:

var tmp = document.createElement("DIV");
tmp.innerHTML = "<div class='chk'>Some content...</div>";
alert(tmp.innerText);

Using regx:

var txt = "<div class='chk'>Some content...</div>";
alert(txt.replace(/(<([^>]+)>)/ig,""));

Reference: https://css-tricks.com/snippets/javascript/strip-html-tags-in-javascript/

Not the answer you're looking for? Browse other questions tagged or ask your own question.