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

124
Views
Cant Copy Text To Clipboard

I am using hadlerbars as the view engine for express and i want the text in the variable code to be copied to the clipboard i tried many solutions . This is my current code

function copyLink() {
    var copytext = document.getElementById('alcslink').innerHTML
    let code = copytext.split(":- ").pop() /*formatted */
    code.select();
      code.setSelectionRange(0, 99999); /* For mobile devices */
    
       /* Copy the text inside the text field */
      navigator.clipboard.writeText(code.value);
    
}

when i run this it gives me this error in the web console

 TypeError: code.select is not a function
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This is how I use it:

Note, it does not work in the snippet engine. You will need to add it to your code. Sorry.

const writeToClipboard = async (txt) => {
  const result = await navigator.permissions.query({ name: "clipboard-write" });
  if (result.state == "granted" || result.state == "prompt") {
    await navigator.clipboard.writeText(txt);
    console.log('Copied to clipboard');
  }
};

document.querySelector('button').addEventListener('click', async () => {
 const el = document.querySelector('div');
 await writeToClipboard(el.innerHTML);
});
<div>copy me</div>
<button>Click</button>

about 4 years ago · Santiago Trujillo 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!