jeudi 31 janvier 2019

jQuery: Sometimes random fails

I have a blog which advertises x3 articles randomly at the bottom of each post. Sometimes, this feature fails to display all 3 (1 missing).

I can't see where the problem lies.

JQuery

$.get("https://www.citychurchchristchurch.co.nz/blog.php", function(data) {
    var $quotes = $(data).find(".container-articles-5"),
      count = $quotes.length,
      $random = function() {
        return $quotes.eq(Math.floor(Math.random() * count));
      };
    $(".blog-ad-1").append($random);
});

HTML (where ads are displayed)

<aside class="blog-ad-4">
    <div class="blog-ad-5">
      <div class="blog-ad-3">
        <div class="blog-ad-1"></div>
      </div>
      <div class="blog-ad-3">
        <div class="blog-ad-1"></div>
      </div>
      <div class="blog-ad-3">
        <div class="blog-ad-1"></div>
      </div>
    </div>
</aside>

All 3 ads should display. View live demo here (near the bottom): https://www.citychurchchristchurch.co.nz/blog/eo-cycling-20181030




Aucun commentaire:

Enregistrer un commentaire