I want generate one tags when click the button, but unfortunately the tag only displays after the page load, but not when I click the button. can anyone help me?
const tags = ['#tiktok', '#twitter', '#facebook', '#instagram', '#hot', '#youtube'];
let btn = document.getElementById("btn");
btn.addEventListener("click", myFunction(tags));
function myFunction(array) {
var out = [];
var out = array[Math.floor(Math.random() * array.length)];
alert(out);
}
<div class="card-header bg-danger text-white">
<strong>tags</strong>
<button id="btn" class="btn-primary">Generate</button>
</div>
Aucun commentaire:
Enregistrer un commentaire