Generate random numbers Jquery

Modelesq

I'd like to show a random numbers within my list. Im grabbing the list from the backend, and im just using these numbers as examples. This is my code, I'm not quite sure why its not filling in the text.

setInterval(function() {
    var number = 1 + Math.floor(Math.random() * 6);
    $('.num-gen').text(number);
},

Made a fiddle here to show you what I'm working with. Thanks in advance.

PhilTrep

You had an error in your code, you were missing the finishing , 1000/*time in ms*/);!

Also, jQuery is not required here, you may do this in Javascript like this.

setInterval(function() {
    var number = 1 + Math.floor(Math.random() * 6);
    document.getElementsByClass('num-gen')[0].innerHtml = number;
}, 1000);

EDIT:

setInterval(function() {
    jQuery.each(jQuery('.num-gen'),function(){
         var number = 1 + Math.floor(Math.random() * 6);
         jQuery(this).text(number);  
    });
}, 1000);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related