WIK Posted January 31, 2021 Report Share Posted January 31, 2021 in output imi creaza un tag "textarea" unde selecteaza si copiaza datele, si ramane acolo, mai apoi daca spamez "copy" se creaza "textarea" de fiecare data stie cineva cum pot sa nu mai creeze un tag propri zis sau dupa ce il creaza sa il foloseasca si dupa sa il sterga ? si asta-i codul <script>function copyFunction() { const copyText = document.getElementById("myInput").textContent; const textArea = document.createElement('textarea'); textArea.textContent = copyText; document.body.append(textArea); textArea.select(); document.execCommand("copy"); document.reset(textarea); } document.getElementById('button').addEventListener('click', copyFunction); </script> Quote Link to comment Share on other sites More sharing options...
Wav3 Posted January 31, 2021 Report Share Posted January 31, 2021 De ce creezi textarea? Pune-l mereu in pagina dar cu display: none. 1 Quote Link to comment Share on other sites More sharing options...
WIK Posted January 31, 2021 Author Report Share Posted January 31, 2021 9 hours ago, Wav3 said: De ce creezi textarea? Pune-l mereu in pagina dar cu display: none. Din moment ce folosesc bootstrap pot da display:none la <textarea> ? deoarece am asa cv intr-un pseudo css da nu il da ca si display none, sau asta trebuia facuta in JS ? Quote Link to comment Share on other sites More sharing options...
Wav3 Posted January 31, 2021 Report Share Posted January 31, 2021 N-are nici o legatura ca folosesti bootstrap. Din cate inteleg tu adaugi acel textarea doar ca sa copiezi textul din el, deci nu-ti trebuie css sau vizibilitate. Ii poti pune style="display: none;" sau class="hide" ca parca asa e in BS. Si folosesti acelasi textarea pentru toate copierile. 1 Quote Link to comment Share on other sites More sharing options...
UnixDevel Posted January 31, 2021 Report Share Posted January 31, 2021 17 hours ago, WIK said: Ia incearca asta <script>function copyFunction() { const copyText = document.getElementById("myInput").textContent; const textArea = document.createElement('textarea'); textArea.setAttribute("id", "customID"); textArea.textContent = copyText; document.body.append(textArea); textArea.select(); document.execCommand("copy"); document.reset(textarea); /// var elem = document.querySelector('#customID'); elem.parentNode.removeChild(elem); } document.getElementById('button').addEventListener('click', copyFunction); </script> 1 Quote Link to comment Share on other sites More sharing options...
WIK Posted January 31, 2021 Author Report Share Posted January 31, 2021 am gasit pe net o solutie nu stiu daca ma complic sau nu, dar momentan sunt incepator, var css = 'textarea { display: none; }', head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } si functioneaza ! Multumesc mult pentru ajutor ! Quote Link to comment Share on other sites More sharing options...