Reputation: 12949
I'm creating an mobile app (PhoneGap) where there are news that the user can edit. The content of the news is in HTML and when the user wants to edit the news it switches to a Form Panel and sets the value of a text area to the content value of the news. The problem is I get HTML tags in the text area. So my question is, is there a way to remove/hide these tags from the content of the news ?
I have tried slash nick's technique but when I do :
console.log(record.data.content.textContent);
I get
*** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSRangeException> *** -[JKArray objectAtIndex:]: index (1) beyond bounds (1)
Thanks
Upvotes: 0
Views: 1860
Reputation: 12949
I finally went for that method even though it removes all HTML tags as well
Strip HTML from Text JavaScript
Upvotes: 1
Reputation: 26549
You could use textContent
on the element to get it's text. This will work in Firefox, Chrome and IE9. For older versions IE you can use innerText
.
var text,
editElement = document.getElementsById("elementToEdit");
if (editElement.textContent) {
text = editElement.textContent;
} else {
text = editElement.innerText;
}
document.getElementsByTagName("textarea")[0].value = text;
However, this will remove any tags within the content and just leave the text.
Upvotes: 1
Reputation: 23866
You can embed an editor like TinyMCE or NicEdit to your application.
Upvotes: 0