views:

78

answers:

2

Im trying to put a variable in a selector but it doesn't work what am i doing wrong?

<a class="button left" href="#">left</a>
<a class="button right" href="#">right</a>


$('.button:not(.disable)').show(); //Works

var oButtons = $('.button');
$(oButtons+':not(.disable)').show(); //Doesn't Work why?
+8  A: 

because you are trying to pass a jquery object into another jquery object. what you want to do is this:

var oButtons = '.button';
$(oButtons+':not(.disable)').show();
GSto
cant i deobjectify :p oButtons ?
Wieringen
oButtons does not need to be a jQuery object; it just needs to be a string (as GSto's code shows). Thus, there is no need to "de-objectify" it.
qwertypants
The $() selector syntax only needs a string If you want to make a jQuery object for later use, then by all means, do so... var Buttons = '.button'; var oButtons = $(Buttons+':not(.disable)'); ... oButtons.show();
Frank DeRosa
+2  A: 

well you could use something like this:

var oButtons = $('.button');
oButtons.filter(':not(.disable)').show(); //Notice the filter option
Ramuns Usovs