我正尝试将代码here应用于我的document,以便在用户执行过滤操作时隐藏不需要的rideshare-item
div(而不是rideshare-detail
)。我认为这取决于我将div元素作为目标的方式,但我不确定。
有人可以指点我正确的方向吗?如何定位jsfiddle到document?
中的元素到目前为止,这是我的代码:
$('body').on('click', '#go-button', function(event){
// Collect values
var startAddress = $('.start-address').val();
var destinationAddress = $('.end-address').val();
// Only show matching pickup address and waypoint
$('.rideshare-item').show();
$('.rideshare-detail .waypoint').each(function(a,b){
var waypoint = $(b).attr('waypoint');
// if found
if((waypoint == startAddress) || (waypoint == destinationAddress)){
return false;
}
// if not found
else if($((waypoint != startAddress) && (waypoint != destinationAddress)) && a == $('.rideshare-detail .waypoint').length-1) {
$(this).closest('.rideshare-item').hide();
}
});
});