I have the html page. In that HTML page, Iust want to clone all elements like head,body and other elements . I can able to get like this
const getHeadEle = () => {
const newHead = document.head.cloneNode(true);
return newHead.innerHTML;
}
const getBody = () => {
const head = document.head.cloneNode(true);
const dom = document.createElement('div');
dom.innerHTML = document.body.innerHTML;
return dom.innerHTML;
}
const html = `<!doctype html><html lang="en"><head>${getHeadEle()}</head><body>${getBody()}</body></html>`;
For now, I get the head element and body element into separate method. Is possible to clone all documents in a line of code?
try it ...
const getdocument = () => {
const newDocument = document.cloneNode(true);
return newDocument ;
}
const html = getdocument() ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.