vendredi 27 mars 2020

Display random div from X divs selected by CSS-Class

I have, on a homepage, X html div elements in one page, with X different classnames:

  • class="home-1"
  • class="home-2"
  • class="home-3"
  • class="home-4"
  • etc.

My goal is, to dislpay only one of these "divs" randomly, so when the page is refreshing, everytime a randomly different div is displayed. The rest should be hidden. it would be very nice if the same div was not shown twice in a row I think, i can't do this, only with css.

what i manually can do is

.home-1 { display: none; }
.home-3 { display: none; }
.home-4 { display: none; }

So in this Case home-2 is displayed.

Of course i want that automated with javascript, can someone please help me?

that yould be very nice!




Aucun commentaire:

Enregistrer un commentaire