I have written following code to find and get the div
element with id vcr_data
from html string
. When I try to append that div
to html
tag, it's getting printed as follows instead of the stringified div
:
... <body>[object HTMLDivElement]</body></html>
code snippet:
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);
Just clone the container whose nodes you want to copy and get the nodes from the copied one, if you want to make the original container intact. And you are putting them into the array and then running a loop multiple times instead you can run a loop once and simultaneously put them in your . slider class.
To convert a HTMLElement to a string with JavaScript, we can use the outerHTML property. const element = document. getElementById("new-element-1"); const elementHtml = element.
HTMLDivElement.align. A string representing an enumerated property indicating alignment of the element's contents with respect to the surrounding context. The possible values are "left" , "right" , "justify" , and "center" .
Use .outerHTML
to get the HTML of the DIV.
<body>${doc.getElementById('vcr_data').outerHTML}</body>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With