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

69
Views
How do I copy text from h1 onto clipboard with a button

Here is the Javascript code. I need to copy all of numlength. (so the 5 random letters)

let numberArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
let boxEl = document.getElementById("numberbox-el")


let numlength = 5

function generate() {
    let generateNum = Math.floor(Math.random() * numberArray.length)
    
    return numberArray[generateNum]
}

function displayNum() {
    let display = ""
    for (let i = 0; i < numlength; i++) {
    display += generate()
    }
    boxEl.textContent = "Characters: " + display

}

Here is the HTML code, I am trying to create a button that copys <h1 to my clip board

<html>
    <head>
        <link rel="stylesheet" href="cssnumbergen.css">
    </head>
<body>
<h1 id="numberbox-el" >Characters:</h1>
<button id="generateNum" onclick="displayNum()" >Generate Characters!</button>

<script src="NumberGen.js"></script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

navigator.clipboard.writeText(document.querySelector("#numberbox-el").innerText)

This will work for most browser.

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!