0

I am caching a selector into a jquery variable, like so:

var elem = $('.wrapper');

I want to perform different queries on the variable according to certain properties. gt(0), :visible, :hidden etc.

By my reckoning, it should look like this:

var elemHidden = $(elem+':hidden');

Of course this is not working. I am assuming it is simple, or something quite close to the code I have.

Here is a jsfiddle: http://jsfiddle.net/lharby/5m7nf97r/

Here is some HTML:

<div class="wrapper">Wrapper 1</div>
<div class="wrapper">Wrapper 2</div>
etc..

2 Answers 2

3

You can not concatenate a jQuery object and a string. You want to use filter to reduce the set.

var elemHidden = elem.filter(':hidden');
Sign up to request clarification or add additional context in comments.

Comments

1

You should use the $.is() method:

elem.is(':hidden');
elem.is(':visible');
elem.is(':checked');

And for other specific methods as $.gt()

elem.gt(0); or $(elem).gt(0)

2 Comments

The is method is is going to return a boolean, I do not think that is what OP wants.
Thank you. This method does work. Or it did in the code I was testing at least.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.