mardi 1 septembre 2020

JavaScript getElementsByClassName: replace take radom 5 of 10 and shuffle

I have:

<div class="parent">
  <div class="myItem">Item 1</div>
  <div class="myItem">Item 2</div>
  <div class="myItem">Item 3</div>
  <div class="myItem">Item ...</div>
  <div class="myItem">Item 10</div>
</div>

I want:

<div class="parent">
  <div class="myItem">Item 7</div>
  <div class="myItem">Item 4</div>
  <div class="myItem">Item 5</div>
  <div class="myItem">Item 9</div>
  <div class="myItem">Item 2</div>
</div>

I would like to replace a certain amount (for example 5 of 10) items. And the replaced items shuold be in a new, random order. In pure JavaScript. Whats the best way to do this?




Aucun commentaire:

Enregistrer un commentaire