2013-02-27 111 views
-6

我看过类似的例子,但不知道如何让我的代码中使用“not(this)”。
基本上我需要做的是:
目标儿童元素,但在点击(this)一个目标儿童元素,但不是被点击的元素

这里的不是那些是我已经尝试:

jQuery(document).ready(function(){ 
    jQuery("li").click(function(){ 
     jQuery(this).children('.step').slideToggle("slow"); 
     jQuery not(this).children('.step').slideUp("slow"); // any advice?... 
    }); 
}); 
+2

您的代码是没有意义的。你想做什么? – SLaks 2013-02-27 17:09:38

+3

你想做什么?你的问题是什么? – 2013-02-27 17:09:38

+0

HTML代码会清除很多情况 – 2013-02-27 17:16:04

回答

2

使用.siblings()

(function($){ // REMAP "$" to jQuery 
$(function(){ // DOM READY shorthand 
    $("li").click(function(){ 
     $(this).slideDown(800).siblings().slideUp(800); 
    }); 
}); 
})(jQuery); 

或者你的情况可能是这个(我不知道,因为它有点不清楚)

$("li").click(function(){ 
    $(this).find('.step').slideToggle(800); 
    $(this).siblings().find('.step').slideUp(800); 
}); 

jQuery API Documentation - Siblings

+0

很酷。这样可行。非常感谢roXon! – 2013-02-27 18:07:01

+0

@AdamUlivi欢迎您!感谢您的反馈 – 2013-02-28 07:45:14