JQuery toggle does not work

i like to toggle .toggle-item-(number here) with .link(number here) . At the beginning all .toggle-item s are closed. Only one toggle item should be shown at the same time. Every time a new toggle item opens an other open toggle item should close.

Link with code is here: http://jsfiddle.net/rAUqb/

Why does the jQuery code not work?

Updated Marc's code so it closes the others when clicking.

$(document).ready(function() {
    $('[class^=toggle-item]').hide();
    $('[class^=link]').click(function() {
        var $this = $(this);
        var x = $this.attr("class");
        var className = '.toggle-item-' + x.replace('link', '');
        $(className ).toggle();
        $('[class^=toggle-item]:not('+className +')').hide();
        return false;
    });
});
我来评几句
登录后评论

已发表评论数()

相关站点

+订阅
热门文章