I am using the periodic updater plug-in to make an Ajax call to grab
an HTML file that has many divs in it. I want to parse the returned
HTML and display a random div in a placeholder div on the page. I am
stuck on how to select out the random div from the returned HTML. Can
someone please lend a hand on this?

$(document).ready(function() {
        $.PeriodicalUpdater({
                      url : '/common/inc/contentPieces.htm',
                          method: 'get',
                          minTimeout: 12000,
                          maxTimeout: 15000
                   },
                   function(data){
                          //select random div to show from returned data
                          var totalDivs = $(data).children('div').size();
                          var rand = Math.ceil(Math.random() *
totalDivs);
                          /***** THIS IS WHAT I AM NOT SURE HOW TO DO
*****/
                          
$('#contentRefresher').html($(data).children("div:eq(" +
rand + "'"));
                          $('#contentRefresher').show('slide', 'slow');
                          $('#contentRefresher').effect('highlight', {color: 
'#fffacd'},
3000);
                });
    });


Returned HTML
<div id="div1">
<h5>Div 1</h5>
<p>This is div 1</p>
</div>
<div id="div2">
<h5>Div 2</h5>
<p>This is div 2</p>
</div>
<div id="div3">
<h5>Div 3</h5>
<p>This is div 3</p>
</div>

Reply via email to