I am having a really weird bug for UIWebView, I load a very simple html into the UIWebView:
[self.webview loadHTMLString:@"<html><body><div id='hello'>hello world</div></body></html>" baseURL:nil];
and then call 4 lines below:
NSString *body = [self.webview stringByEvaluatingJavaScriptFromString:
@"document.getElementsByTagName('body')[0].outerHTML"];
NSString *helloValue = [self.webview stringByEvaluatingJavaScriptFromString:
@"document.getElementByID('hello').value"];
NSString *helloOuter = [self.webview stringByEvaluatingJavaScriptFromString:
@"document.getElementByID('hello').outerHTML"];
NSString *helloInner = [self.webview stringByEvaluatingJavaScriptFromString:
@"document.getElementByID('hello').innerHTML"];
NSString *helloElement = [self.webview stringByEvaluatingJavaScriptFromString:
@"document.getElementByID('hello')"];
Only the first line, using getElementsByTagName return me the correct body html, all other lines just return me an empty string @””. What can go wrong with my code? How can I get the div that has an id of hello
I figured out the problem: it was my stupid misspelling,
getElementByIdinstead ofgetElementByID