JavaScript Selecting random div for auto fade in and fade out

Currently, this code is auto fade in and fade out div by selecting the div element the way they were arranged (consecutive order). What I want to do now is to make the selector in random, I want to fade in a random div and after fading it out it will pick another random div and infinite loop the process. Since I'm new in jQuery and so confused, I also want to know your opinion on how to put this such process on a If Else statement in the easiest way. Like for example, I will get the value of a number

int num = 1;
If(num == 1){
<!-- Do the process-->
}
Else {
<!-- Do another process by selecting from another set of divs-->
}

Here is the code:

    jQuery.fn.nextOrFirst = function (selector) {
    var next = this.next(selector);
    return (next.length) ? next : this.prevAll(selector).last();
}

$(document).ready(function () {
    $('div.mb').fadeOut(500);

    var fadeInTime = 1000;
    var intervaltime = 3000;
    setTimeout(function () {
        fadeMe($('div.mb').first());
    }, intervaltime);

    function fadeMe(div) {
        div.fadeIn(fadeInTime, function () {
            div.fadeOut(fadeInTime);
            setTimeout(function () {
                fadeMe(div.nextOrFirst());
            }, intervaltime);
        });
    }
});

Divs:

 <div class="boxes">
      <div class="mb one">1-------------one</div>
      <div class="mb two">2-------------two</div>
      <div class="mb three">3-------------three</div>
 </div>
Answer:1

Not sure if this is exactly what you want but can be modified:

var mb = $('.mb'),   
mbl = mb.length;

mb.hide();
rand();

function rand(){
  var r = getRand(0, mbl);

  mb.eq(r).fadeIn('slow', function(){
    $(this).fadeOut('slow', function(){
      setTimeout(rand, 200);
    });
  });
}


function getRand(min, max) {
    return Math.floor(Math.random() * (max - min) + min);
}
Answer:2

Try changing the nextOrFirst function to something like:

   jQuery.fn.nextOrFirst = function (selector) {
    var xCount = selector.size();   
    return  Math.floor(Math.random() * xCount ) + 1;
}

Instead of getting the next of first div, this gets a count of all of the divs, and pics a random number between 1 and X(the number of divs with your selector)

Answer:3

I want to get the background color of a DIV element when I click on that div. HTML - <div style="background-color:red" ng-click="getFilter($event)" class="agenda col-md-4">ABCDEGF/div> JS ...

I want to get the background color of a DIV element when I click on that div. HTML - <div style="background-color:red" ng-click="getFilter($event)" class="agenda col-md-4">ABCDEGF/div> JS ...

  1. change background color angularjs
  2. ngstyle background color angularjs
  3. set background color angularjs
  4. dynamic background color angularjs
  5. body background color angularjs
  6. change div background color angularjs
  7. change background color using angularjs
  8. add background color in angularjs
  9. change background color dynamically angularjs
  10. change background color onclick angularjs
  11. angularjs background color function

I have the following code to check if a username already exists. It uses an AJAX-request to another page, this page returns either 1 (username exists) or 0 (username doesn't exist). function ...

I have the following code to check if a username already exists. It uses an AJAX-request to another page, this page returns either 1 (username exists) or 0 (username doesn't exist). function ...

  1. code vein wait until installation is complete
  2. arduino code wait until
  3. code for wait until element visible
  4. code for wait in selenium webdriver
  5. wait code for selenium
  6. wait code for python
  7. code for wait
  8. code for wait in c#
  9. code for wait in java
  10. wait code for vba
  11. code vein please wait until the installation
  12. vba code to wait until refresh complete
  13. write code for wait until element visible
  14. vba code to wait until workbook opens
  15. vba wait until code executes

I have an asp.net textbox which also works with jquery datepicker. <asp:TextBox ID="tbxFirstReceivedDate" CssClass="selectstyle" runat="server" MaxLength="100" fieldtype='date' Width="200"><...

I have an asp.net textbox which also works with jquery datepicker. <asp:TextBox ID="tbxFirstReceivedDate" CssClass="selectstyle" runat="server" MaxLength="100" fieldtype='date' Width="200"><...

  1. convert string datetime to datetime python
  2. convert string datetime to date python
  3. convert string datetime to datetime c#
  4. convert string datetime to date in java 8
  5. convert string datetime to datetime
  6. convert string datetime to date in c#
  7. convert string datetime to datetime in sql server
  8. convert string datetime to datetime sql
  9. convert string datetime to date java
  10. convert string datetime to datetime java
  11. convert string datetime to long in java
  12. convert string datetime to instant java
  13. convert string datetime to datetime format c#
  14. convert string datetime to utc c#
  15. convert string datetime to localdatetime in java
  16. convert string datetime to datetime in javascript
  17. convert string datetime to timestamp java
  18. convert string datetime to calendar in java

In javascript I need to check whiwh value user enter in an html input like this: <input type="text" id="volume" class="form-control" name="voilume"></input> <div id"button"></...

In javascript I need to check whiwh value user enter in an html input like this: <input type="text" id="volume" class="form-control" name="voilume"></input> <div id"button"></...