I found the problem of HTML tags inside a String, the string I take from a SharePoint RTE-field:
var clientContext;
var list;
var item;
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
// Create an instance of the current context.
function sharePointReady() {
clientContext = SP.ClientContext.get_current();
list = clientContext.get_web().get_lists().getByTitle("Prova Scheda");
var itemId = parseInt(GetUrlKeyValue('ID'))
item = list.getItemById(itemId);
clientContext.load(item);
clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
}
function onRequestSucceeded() {
var corpo = item.get_item('Corpo');
var corpoOr = item.get_item('CorpoOriginale');
corpoOr = corpoOr.replace("<p>", "").replace("<div>", " ").replace("<br>", "\n").replace("<html>", " ").replace("</p>", "").replace("</div>", "").replace("</html>", "");
corpo = corpo.replace("<p>", "").replace("<div>", " ").replace("<br>", "\n").replace("<html>", " ").replace("</p>", "").replace("</div>", "").replace("</html>", "");
console.log(corpo + " " + corpoOr);
}
function onRequestFailed(sender, args) {
console.log('Error: ' + args.get_message());
}´
taking the variable "corpo" returns a String with the html Tags to the internal one, provide with: corpo.textContent
, corpo.innerText
and corpo.outerHtml
but in the 3 cases it returns an indefinite value.
in the code that I put, as you can see I am using the replace()
but it also returns the html tags as you can see in the screenshot
how to clean all the tags and leave only the testo?