Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
How do I copy text to the clipboard in JS?

I would like to put a copy paste on the email, when clicking on the email, the email is copied automatically. I've tried several techniques but I can't.

Here is my code:

    content += '<table class="table"><thead><tr><th>Nom</th><th>Prénom</th><th>Companie</th><th>Tags</th><th class="copy">Email</th></tr></thead><tbody>';

    JSON.parse(data).forEach(id => {
     
      content += '<tr>';
      content += '<td>' + id.lastname + '</td>';
      content += '<td>' + id.firstname + '</td>';
      content += '<td>' + id.company + '</td>';
      content += '<td>' + id.tags + '</td>';
      content += '<td>' + id.email + '</td>';
      content += '</tr>';
    });

    
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

the main issue come from this line let mail = tabStudents.email; tabstudents is not define and in the process you try to do it's from the iterator of the foreach loop

in my sample i renamed it student

JSON.parse(data).forEach(student => {
let mail = student.email;

here the full sample

function displayPopup(data) {
  if (data) { // si data n'est pas vide
    let content = '';

    let modal = document.getElementById("myModal");
    let contentModal = document.getElementById("modal-body");
    let span = document.getElementsByClassName("close")[0];

    content += '<table class="table"><thead><tr><th>Nom</th><th>Prénom</th><th>Companie</th><th>Tags</th><th class="copy">Email</th></tr></thead><tbody>';

    JSON.parse(data).forEach(student => {
      let mail = student.email;
      console.log(mail)
      content += '<tr>';
      content += '<td>' + student.lastname + '</td>';
      content += '<td>' + student.firstname + '</td>';
      content += '<td>' + student.company + '</td>';
      content += '<td>' + student.tags + '</td>';
      content += '<td>' + student.email + '</td>';
      content += '</tr>';
    });

    content += '</tbody></table>';

    contentModal.innerHTML = content;
    modal.style.display = "block"

    span.onclick = function() {
      modal.style.display = "none";
    }

    window.onclick = function(event) {
      if (event.target == modal) {
        modal.style.display = "none";
      }
    }
  }
}

displayPopup('[{"id": 1, "email":"test@test.r"}]');
<div id="myModal">
  <div id="modal-body">
    <span class="close"></span>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda