Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!