假设我有以下选择器:
var slots = $('.clinic-branch-2.doctor-has-specialty-3').parent().siblings();
给了我这个结果:
[div.col-xs-3.col-sm-3.col-md-2, div.col-xs-4.col-sm-4.col-md-4.slots-go-here, prevObject: m.fn.init[1], context: document]
我需要选择.slots-go-here
元素。
我尝试使用[1]
索引访问它,但它返回原始HTML。稍后我需要在我的选择上拨打.html(someHtmlString)
。我怎么能这样做?
答案 0 :(得分:2)
$.siblings
可以选择一个。 see docs
$('.clinic-branch-2.doctor-has-specialty-3').parent().siblings('.slots-go-here');
答案 1 :(得分:1)
您可以将选择器传递给.siblings()
方法
var slots = $('.clinic-branch-2.doctor-has-specialty-3').parent().siblings('.slots-go-here');
slots.html('Do Something')
答案 2 :(得分:1)
Yo可以将类选择器添加到siblings():
var slots = $('.clinic-branch-2.doctor-has-specialty-3').parent().siblings('.slots-go-here');