try something like this
-(void)appendTagToBody:(NSString *)tagName InnerHTML:(NSString *)innerHTML
{
@try {
// Gets a list of all <body></body> nodes.
DOMNodeList *bodyNodeList = [[[self mainFrame] DOMDocument] getElementsByTagName:@"body"];
// There should be just one in valid HTML, so get the first DOMElement.
DOMHTMLElement *bodyNode = (DOMHTMLElement *) [bodyNodeList item:0];
// Create a new element, with a tag name.
DOMHTMLElement *newNode = (DOMHTMLElement *) [[[self mainFrame] DOMDocument] createElement:tagName];
// Add the innerHTML for the new element.
[newNode setInnerHTML:innerHTML];
// Add the new element to the bodyNode as the last child.
[bodyNode appendChild:newNode];
[newNode scrollIntoView:YES];
}
@catch (NSException *exception) {
}
}
also if you wanted to append specific to a div, probably you need to change getElementsByTagName to getElementsById
Its working for me.