سؤال

what I want to happen is that if you click on a link a specific div will be shown and when clicking on it again it will be hidden. And even if you click on another link the div will also be hidden and the other one will be shown. I've found this code on internet but it says that it will toggle the next ".toggle" and the div that I want to be shown isn't the next one.

$(function () {
    $('.toggle').hide();
    $('a.togglelink').on('click', function (e) {
        e.preventDefault();

        var elem = $(this).next('.toggle')
        $('.toggle').not(elem).hide('slow');
        elem.toggle('slow');
    });
});

But what I want is that I have a left bar and a right bar and when I click for example on 1, a div on the right side will open. When I click on 3, 1 will close and 3 will open, etc.

Here's a JSFiddle, I just copied my whole CSS and a part of my HTML so I'm sorry if it is a bit sloppy. But maybe you know what I mean with left and right now.

هل كانت مفيدة؟

المحلول

Demo

Above demo is to give you a fair idea of .hide(), .show() and .toggle(). You need to use .toggle()

Revert back if some confusion.

نصائح أخرى

Use below :

 $("a").click(function(){
      $("a").toggle();   
    });
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top