i was just wondering if there is anyway i could copy text from a div with same class name into an input field
i am trying to copy each name one by from the div with same class name into an input field
function copyname() {
var elems = document.getElementsByClassName("hud-leaderboard-party");
var lastElem = elems[elems.length - 1];
document.getElementsByClassName("hud-intro-name")[0].value = lastElem.innerText;
}
<div class="hud-intro-leaderboard-parties">
<div class="hud-leaderboard-party">NAME HERE 1, NAME HERE 2, NAME HERE 3, NAME HERE 4 — <strong>Random numbers</strong></div>
<div class="hud-leaderboard-party">NAME HERE 1, NAME HERE 2, NAME HERE 3, NAME HERE 4 — <strong>Random numbers</strong></div>
<div class="hud-leaderboard-party">NAME HERE 1, NAME HERE 2, NAME HERE 3, NAME HERE 4 — <strong>Random numbers</strong></div>
<div class="hud-leaderboard-party">NAME HERE 1, NAME HERE 2, NAME HERE 3, NAME HERE 4 — <strong>Random numbers</strong></div>
<div class="hud-leaderboard-party">NAME HERE 1, NAME HERE 2, NAME HERE 3, NAME HERE 4 — <strong>Random numbers</strong></div>
</div>
<br>
<input type="text" class="hud-intro-name" maxlength="50" style="width: 100%;">
<br><br>
<button class="btn btn-green" style="width: 100%;" onclick="copyname();">COPY NAME</button>
i got it where it will copy all text from div to input on button click but i was wondering is there a way i can only copy one name from the div to input and if button is click again copy next name from div into input and so?