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();
    });
});
4

2 回答 2

2

该版本的 toggle() 在 jQuery 1.7 中已弃用,并在 1.9 中删除,请尝试以下操作:

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

小提琴

于 2013-02-28T23:10:02.953 回答
0

给你:http: //jsfiddle.net/DWwKs/8/

只需添加$('.interest-group').hide();到第一个功能

于 2013-02-28T23:08:34.467 回答