* Graham * Keyarn wrap it in a 'for' loop
<script> var x = document.getElementsByClassName("myads");
for (i=0;i < 2;i++){
........
}

although it could overwrite the same element
so think of the setting as a maximum
If you want it so there are always the same number of ads
<script> var ads = document.getElementsByClassName("my_ads");
for (i=0;i < 3;i++){
var ad = Math.floor(Math.random() * ads.length);
if (ads[ad].innerHTML==''){
ads[ad].innerHTML = 'the ad code goes here';
}else{
i--;}}
</script>

Copy code
If the ad has already been set it repeats the iteration by subtracting 1 from the loop count
2017-02-19 15:51 (edited 2017-02-19 16:27 by Graham ) · (0)

Online: Guests: 1