I am trying to print HTML with this JavaScript in the webview, however it is literally printing <p>HELLO</p>. How can I fix that?
NSString* statement = [NSString stringWithFormat:@"document.getElementById('test').innerText = '<p>HELLO</p>'"];
[self.myWebView stringByEvaluatingJavaScriptFromString:statement];
I guess you need to use
innerHTMLinstead ofinnerText.Because
innerTextwill simply assign whatever you write there. If your text contains html and you element parse that HTML than you have to use innerHTML for sure.Try as follow, may be it will help.
Note
Your test element must be supporting innerHTML property like div span etc.