我已经写了下面的代码来查找和获取div元素编号vcr_data从html string。当我尝试将其附加div到html标签时,它会按如下方式打印而不是字符串化div:
... <body>[object HTMLDivElement]</body></html>
Run Code Online (Sandbox Code Playgroud)
代码片段:
let doc = new DOMParser().parseFromString(html, 'text/html');
console.log('div element ', doc.getElementById('vcr_data'));
const response = `<!DOCTYPE html>
<html>
<head>
<style id="jss-server-side"></style>
</head>
<body>${doc.getElementById('vcr_data')}</body>
</html>`;
console.log('html: ', response);
Run Code Online (Sandbox Code Playgroud)