1

I am using JQUery 1.7.1 to toggle a div named .interest-group. When you click a link it opens the next div named .interest-group. Right now, you can toggle all of the .interest-group divs to be visible, but I would like to make it that only one can be visible at a time. How can I do this?

JSFIDDLE: http://jsfiddle.net/DWwKs/6/

Here is my JQuery:

$(document).ready(function () {
    $('.interest').toggle(

    function () {
        $(this).next('.interest-group').show();
    },

    function () {
        $(this).next('.interest-group').hide();
    });
});
1
  • Toggle don't get function as first argument (as far as i know): api.jquery.com/toggle Commented Feb 28, 2013 at 23:08

2 Answers 2

2

That version of toggle() was deprecated in jQuery 1.7, and removed in 1.9, try this instead :

$(document).ready(function () {
    $('.interest').on('click', function(e) {
        e.preventDefault();
        $('.interest-group').hide();
        $(this).next('.interest-group').toggle();
    });
});

FIDDLE

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

Comments

0

Here you go: http://jsfiddle.net/DWwKs/8/

Just add the $('.interest-group').hide(); to the first function

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.