Jump to content
WIK

[JAVASCRIPT] remove textarea element

Recommended Posts

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  ?download.png

 

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>

 

Link to comment
Share on other sites

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 ? 

Link to comment
Share on other sites

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.

  • Thanks 1
Link to comment
Share on other sites

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>

 

 

  • Thanks 1
Link to comment
Share on other sites

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 ! 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...