0

Sorry, I didnt explain this very well, I've set up what I have in jsfiddle...

http://jsfiddle.net/greggb/Ya2wX/

basically what I'm trying to do is make it so after the first div has been opened, the second tab anchor (two) will close the first div before opening the next div?

Thanks, Gregg.

 $(document).ready(function() {
      $('.example2').hide().before('');
      $('a#toggle-example2').click(function() {
           $('.example2').slideToggle(500);
           return false;
      });
 });

 $(document).ready(function() {
      $('.item1').hide().before('');
      $('a#toggle-item1').click(function() {
           $('.item1').slideToggle(500);
           return false;
      });
 });
2
  • What does the before('') do ??? Commented Aug 24, 2012 at 16:34
  • 1
    Show us html or put it on jsfiddle.com Commented Aug 24, 2012 at 16:34

4 Answers 4

1
$('a#toggle-item1').click(function() {

An id should uniquely identify one element in a page . . . .if you are using ID 'toggle item 1' for other divs this won't work . . . .try using unique ids or a class

Sign up to request clarification or add additional context in comments.

Comments

0
 $(document).ready(function() {
      $('.item1').hide();
      $('.item1').click(function() {
           $('.item1').not(this).hide();
           $(this).slideToggle(500);
           return false;
      });
 });

Comments

0

Set a toggle_item class on the <a> elements, and do:

<a href="#" class="toggle-item">link 1</a>
<div class="item">content 1</div>

<a href="#" class="toggle-item">link 2</a>
<div class="item">content 2</div>

js:

$(function() {
      $('.item').hide();
      $('a.toggle-item').click(function() {
           $(this).next('.item').slideToggle(500);
           return false;
      });
});

FIDDLE

Comments

0

There may be a shorter method but this should work (demo: http://jsfiddle.net/6N4kJ/13/):

// When item 1 is clicked           
$('#item1').click(function() {
    // if item 2 is visible
    if ($('.item2').is(':visible')) {
        // hide (toggle) item2, and when finished..
        $('.item2').slideToggle(500, function() {
            // toggle item1
            $('.item1').slideToggle(500);
        });
    // else, just hide item1
    } else {
        $('.item1').slideToggle(500);
    }
});

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.