Shawn Mclean
Shawn Mclean

Reputation: 57469

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

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

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

Is this possible?

Upvotes: 1

Views: 76

Answers (1)

Brad Christie
Brad Christie

Reputation: 101614

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.

Upvotes: 3

Related Questions