I have something like this
public render(){
let htmlRender = "<html><body><h2>Children</h2>Joe has three kids:<br/><ul><li>Linn Fenimore Cooper Cary (married writer <a href='Ved Mehta'>Ved Mehta</a> in 1983)</li><li>kid2</li><li>kid3</li></ul></body></html>";
const doc = new DOMParser().parseFromString(htmlRender,'text/html');
let ele = doc.evaluate("/html/body/ul/li[1]/a[1]", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
ele.singleNodeValue.style.background = 'pink';
return (
<div className="details-block context-block">
<h5>Context</h5>
<div dangerouslySetInnerHTML={{__html:doc.body.toString()}} /> --> This returns [object HTMLBodyElement]
</div>
);
}
This is what I am doing above - Taking a html string converting it into a HTML object. Then parsing that using Xpath. Manipulating it(adding the color) and then I want to display it. But it appears as [object HTMLBodyElement]
. what am I doing wrong?
Thanks for the help!