The problem is that .text()
is a method of jQuery objects (which contain nodes), and .textContent
is a property of nodes. Instead, it seems that item.description
is a string.
Then, you could create a DOM element with the string as its html, and then use .textContent
or .text()
. But that is a vulnerable practice:
$('<img src="//" onerror=alert("hacked!") />');
The safe way is:
function stripHTML(html) {
var sandbox = document.implementation.createHTMLDocument().body;
sandbox.innerHTML = html;
return sandbox.textContent;
}
/* ... */
description: stripHTML(item.description).substring(0,350);
/* ... */
Note document.implementation.createHTMLDocument
doesn't work on old browsers.