0

HTML:

<div class="showcase">
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
</div>

<div class="showcase" style="display: none;">
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
</div>

<div class="showcase" style="display: none;">
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
       <a href="#"><img src="img/uploads/testchair.jpg" alt="" /></a> 
</div>

JavaScript:

$(document).ready(function() {
    $('.click').click(function() {
       $('.showcase').fadeOut('fast'); 
       $('.showcase').next('.showcase').show('fast');
    });
});

that is how my code is right now the only problem is when I press the div... the next 2 showcases are showing up I want to just the next showcase en when it is clicked again the next showcase div, how can I do this? :)

1
  • 2
    Where is the element with class='click'? Commented Jul 31, 2011 at 16:58

4 Answers 4

1

Here you go: http://jsfiddle.net/MDEE2/1/

Basically, I added a variable to track which of the showcases that are currently being viewed, and then I just took the next one and made it pop-up.

$(document).ready(function() {
    $('.click').click(function() {
        var active_show = $('.showcase:visible');
        active_show.fadeOut('fast');
        active_show.next('.showcase').show('fast');
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

I think your problem is the $('.showcase') selector is applying to all the 'showcase' 'div' elements on the page. Is it possible for you to work out which 'div' has been clicked within the $('.click').click function?.

Comments

0

First of, $('.click') is not going to work, because there is no element in your HTML with that class. I think this is what you need:

$(document).ready(function() {
    $('.showcase').click(function() {
       $(this).fadeOut('fast'); 
       $(this).next('.showcase').show('fast');
    });
});

Comments

0

$(".showcase") selects all elements with the class showcase. From your code it's hard to tell precisely what you want, but here's some code that will hide the first visible .showcase and show the next one.

$(document).ready(function() {
  $('.click').click(function() {
     $('.showcase:visible').eq(0).fadeOut('fast').next('.showcase').show('fast');
  });
});

References:
:visible
eq() - or .first() - or .filter(":first")

But if all the .showcases are invisible you want to just show the first one. So the whole code is:

$(document).ready(function() {
  $('.click').click(function() {
   if ($('.showcase:visible').length > 0)
     $('.showcase:visible').eq(0).fadeOut('fast').next('.showcase').show('fast');
   else
     $('.showcase').eq(0).show('fast');
  });
});

Working example

And finally, you can probably clean it up to:

$(function() {
    $('.click').click(function() {
        var $visible  = $('.showcase:visible'),
            $showcase = $('.showcase');
        if ($visible.length > 0)
            $visible.fadeOut('fast').next('.showcase').show('fast');
        else
            $showcase.eq(0).show('fast');
  });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.