views:

21

answers:

0

Hi,

I'm having trouble getting some Jquery code to work. I think my problem is stems around how I'm writing the selector.

Here's my original HTML:

<div class="rotate"> 
<div class="offer-holder"><span class="lblSeconds">7</span></div>
<div class="offer-holder"><span class="lblSeconds">3</span></div></div>

...and here's my Jquery code:

$("div.rotate div.offer-holder").hide().eq(1).show();
function rotate() {
    var i = $("div.rotate div.offer-holder:visible").prevAll("div").length + 1;
    i = i % $("div.rotate div.offer-holder").length;
    var speed = $("div.rotate div.offer-holder").fadeOut().eq(i).fadeIn().find('.lblSeconds').text();
    setTimeout("rotate()", (parseInt(speed) * 1000));
};
rotate();

This works perfectly (incidently, in the CSS, the position of offer-holder is set to absolute, top: 0px, left: 0px). BTW, this is an ad rotator. All of the divs overlap each other, then appear one-by-one, looping continuously.

Now, I have to modify it for another page, which looks something like this:

<div class="rotate">
 <div class="ob-offer-item rounded-corners clearfix">
  <div class="test">
   <div class="ob-offer-details">
    <div class="offer-holder"> XXX </div></div></div></div></div>

...and here's what I tried:

$("div.rotate div.ob-offer-item div.test div.ob-offer-details div.offer-holder").hide().eq(1).show();
function rotate() {
    var i = $("div.rotate div.ob-offer-item div.test d div.ob-offer-details div.offer-holder:visible").prevAll("div").length + 1;
    i = i % $("div.rotate div.ob-offer-item div.test d div.ob-offer-details div.offer-holder").length;
    var speed = $("div.rotate div.ob-offer-item div.test d div.ob-offer-details div.offer-holder").fadeOut().eq(i).fadeIn().find('.lblSeconds').text();
setTimeout("rotate()", (parseInt(speed) * 1000));
};
rotate();

I suspect my problem is the prevAll. It's basically hiding every div before it (which, I guess, is what I'm telling it to do). Instead of a nice fade from one ad to the next based on the lblSeconds value, it flickers continuously every second. I don't know the correct syntax to fix the prevAll selector path. I tried several combinations, to no avail.

Any assistance is welcome.

Thanks.

Stephen