在Jquery选择器中添加变量

时间:2017-03-23 11:26:32

标签: jquery variables jquery-selectors

我有这个选择器

self = $('.trim .person:nth-child('+index+')');
self.append('<img src="'+element.profilePic+'" class="profilePic" />');

然后我想在

中选择一个类
  $(self + '.spacer').css('opacity', 0.5);

我也试过

self + $('.spacer').css('opacity', 0.5);

1 个答案:

答案 0 :(得分:4)

将其设为context parameter in jQuery

$('.spacer', self).css('opacity', 0.5);

或者使用find()方法获取当前jQuery对象中的元素。

self.find('.spacer').css('opacity', 0.5);
相关问题