Simple jQuery logic

I think I wrote myself in a corner and don’t know how to backup. I just need to make each div individually closed, as well as close all options.

http://jsfiddle.net/7U9QY/4/

$(function() {
    $('a[href*=#]:not([href=#])').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var target = $(this.hash);
            target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
            if (target.length) {
                $('html,body').animate({
                    scrollTop: target.offset().top
                }, 1000);
                return false;
            }
        }
    });
});

$(function() {
    $('.bar').click(function() {
        $('.full').toggle(600);
    });

});
+3
source share
2 answers

$(function () {
    $('.bar').click(function () {
        $(this).closest('a').next().next().toggle(600);
    });
});


Find the closest tag a, than find the item next nextandtoggle
. closeest ()

Description: for each element in the set, get the first element that corresponds to the selector by testing the element itself and passing its ancestors in the DOM tree.

. next ()

this is a keyword

0
source

, , . , div - /, , div , .full div

$('.full', $(this).parents('div:first')).toggle(600);

: http://jsfiddle.net/7U9QY/5/

0

All Articles