Reputation: 3265
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..
Upvotes: 0
Views: 305
Reputation: 785
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)
Upvotes: 1
Reputation: 207501
You can not concatenate a jQuery object and a string. You want to use filter to reduce the set.
var elemHidden = elem.filter(':hidden');
Upvotes: 3