append child to DOM

result.html

<html>
  <body>
    <div></div>
  </body>
</html>

.cpp

CComPtr<IHTMLDocument2> pDoc;
CComPtr<IHTMLElement>   pBody;
CComPtr<IHTMLDOMNode>   pDomNode;

// get doc to prepare append element in html file
if(FAILED(GetDHtmlDocument(&pDoc)) || !pDoc)
    return;

// get DOM interface of Body to prepare append element in body
if(FAILED(pDoc->get_body(pBody)) || !pBody)
    return;

// access the nodes in the document object model (DOM), to iterate the nodes, to insert nodes, to remove nodes, and to get the attributes of a node.
if(FAILED(pBody->QueryInterface(IID_PPV_ARGS(&pDomNode)) || !pDomNode)
    return;


// create a node and set element id
CComPtr<IHTMLElement> pNewElement;
if(SUCCEEDED(pDoc->createElement(L"div", &pNewElement))){

    // append to body tag
    CComPtr<IHTMLDOMNode> pChildNode;
    CComPtr<IHTMLDOMNode> pChildRef;

    if(SUCCEEDED( pNewElement->QueryInterface(IID_PPV_ARGS(&pChildNode)) )) {
        pDomNode->appendChild(pChildNode, &pChildRef);
}

results matching ""

    No results matching ""