开发者

Adding Toggle Class to this jQuery...?

开发者 https://www.devze.com 2023-02-18 14:55 出处:网络
Can someone help me out with this please? A simple toggle to hide and show areas works perfectly, i need to add a class to the p tag of the one that is open and remove it when its closed.

Can someone help me out with this please?

A simple toggle to hide and show areas works perfectly, i need to add a class to the p tag of the one that is open and remove it when its closed.

Currently this only adds it but it stays added and doesn't remove it, even when you click to close. :(

$(".parents-toggle > p").click(function () {
$(this).toggleClass('open');
   $(".parents-t开发者_高级运维oggle > div.menu-toggle").not($(this).siblings()).slideUp();
   $(this).siblings(".menu-toggle").slideToggle();

});

Any ideas?


Using the DOM inspector on jsFiddle it works fine: http://jsfiddle.net/Gv8Y2/

EDIT:

Try

$(".parents-toggle > p").click(function () {
    $( ".parents-toggle > p").not(this).removeClass("open");
    $(this).toggleClass('open');
    $(".parents-toggle > div.menu-toggle").not($(this).siblings()).slideUp();
    $(this).siblings(".menu-toggle").slideToggle();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消