javascript - Trying to put a variable in a selector in Jquery - Stack Overflow

I'm trying to put a variable in a selector, but it doesn't work, what am I doing wrong?<a

I'm 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?

I'm 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?
Share Improve this question edited Feb 13, 2023 at 12:23 Baijs asked Nov 11, 2009 at 15:20 BaijsBaijs 1,8573 gold badges21 silver badges35 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

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();

well you could use something like this:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742359607a4429125.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信