If you do manage to be able to parse the content, you can use jQuery's
eq() function to get a specific element's index:
http://docs.jquery.com/Selectors/eq

On Jun 30, 12:06 pm, "Cesar Sanz" <[email protected]> wrote:
> As the returned html is not yet part of the document until you append it,
> you cannot use jquery to parse
> it.
>
> You will need to parse the string returned by the server, or append to a div
> and then make all
> your stuffs..
>
> ----- Original Message -----
> From: "zendog74" <[email protected]>
> To: "jQuery (English)" <[email protected]>
> Sent: Monday, June 29, 2009 10:14 PM
> Subject: [jQuery] select random div
>
> > 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