-1

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>
RAlN4
  • 11
  • 4
  • 1
    Does this answer your question? [How do I copy to the clipboard in JavaScript?](https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – evolutionxbox Jul 12 '22 at 00:14

1 Answers1

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

This will work for most browser.

Chang Alex
  • 505
  • 3
  • 11