开发者

How can I add all siblings of the current selector in jQuery

I tried thi开发者_JAVA技巧s but it doesn't work:

$('div').add($(this).siblings());

I want to animate the siblings simultaneously. Can anyone help?


You need to use .addBack() to get both the div and its siblings. In jQuery versions earlier than 1.8, you should use .andSelf() instead, which is now just an alias for .addBack() (thanks Sable).

// jQuery 1.8+
$("#myDiv").siblings().addBack();

// jQuery <1.8
$("#myDiv").siblings().andSelf();
  • http://api.jquery.com/addBack/
  • http://api.jquery.com/andSelf/


This maybe?

$('div').add($(this).siblings('*'));


for animation you can use animate and for adding the siblings please specify whether you want to add the siblings to the jQuery object or to the element itself?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜