开发者

Chaining the JQuery object [$(this)] and other objects

开发者 https://www.devze.com 2023-02-05 19:52 出处:网络
How do I chain the jQuery object with another object such as this: ($(this) AND $(\'#foo\')).hide(); Is this possible开发者_运维知识库?I think you\'re looking for .add()

How do I chain the jQuery object with another object such as this:

($(this) AND $('#foo')).hide();

Is this possible开发者_运维知识库?


I think you're looking for .add()

$(this).add('#foo').hide();

EDIT

Interestingly enough, you can't start with "this". Must be something to do with the element. That having been said (and for now) use the following:

<a href="#">Hide both</a>
<div id="foo">
    Additional content to hide
</div>
$('a').click(function(){
    $('#foo').add(this).hide();
});

Proven to work. Meanwhile, I'm going to see what I can find about why the previous version doesn't work.

0

精彩评论

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

关注公众号