i created a copy button by which you can copy HTML code of a div but problem is that when it coppy inner HTML it also copy spacing of that main HTML I want to copy that code and remove extra spacing
function copyToClipboard(text) {
var dummy = document.createElement("textarea");
document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
}
function copyEvent() {
var elem = document.getElementById("copy").innerHTML;
copyToClipboard(elem)
}
<button type="button" class="btn btn-dark" onclick="copyEvent();"><iconify-icon icon="akar-icons:copy"></iconify-icon>Copy code</button></p>
<div id="copy">
<div class="s-popover ws2 mtn2 p0"
id="products-popover"
role="menu"
aria-hidden="true">
<div class="s-popover--arrow"></div>
<ol class="list-reset s-anchors s-anchors__inherit">
<li class="m6">
<a href="/" class="bar-sm p6 d-block h:bg-black-100 js-gps-track"
data-gps-track="top_nav.products.click({location:2, destination:2})"
data-ga="["top navigation","public qa submenu click",null,null,null]">
<span class="fs-body1 d-block">Stack Overflow</span>
<span class="fs-caption d-block fc-light">Public questions & answers</span>
</a>
</li>
<li class="m6">
<a href="/teams" class="bar-sm p6 d-block h:bg-black-100 js-gps-track"
data-gps-track="top_nav.products.click({location:2, destination:3})"
data-ga="["top navigation","teams submenu click",null,null,null]">
<span class="fs-body1 d-block">Stack Overflow for Teams</span>
<span class="fs-caption d-block fc-light">Where developers & technologists share private knowledge with coworkers</span>
</a>
</li>
<li class="m6">
<a href="https://stackoverflow.co/talent" class="bar-sm p6 d-block h:bg-black-100 js-gps-track"
data-gps-track="top_nav.products.click({location:2, destination:5})"
data-ga="["top navigation","talent submenu click",null,null,null]">
<span class="fs-body1 d-block">Talent</span>
<span class="fs-caption d-block fc-light">
Build your employer brand
</span>
</a>
</li>
</ol>
</div>
</div>
it copy the code with all the spacing and all but I want to avoid that even new line is there any way by which I can avoid that any idea and suggestion will be helpful there Is way by writing like that but i am retrieve some information from database so i have to use django template tag which is not being copied and it create extra spacing