我通常想做的是,检测Trustpilot窗口小部件中的产品是否有0条评论,如果是,则显示Trustpilot中的另一个窗口小部件,该窗口小部件显示我们服务的评论数。
现在,当页面上找到一个名为“ tp-stars--0”的div类时,我将试图隐藏小部件。
这就是我到目前为止所得到的
$('.trustpilot-widget' ).ready(function() {
if($('.tp-widget-stars').find('.tp-stars.tp-stars--0').length) {
$('#tp-widget-wrapper').removeClass('visible');
}
});
<div id="tp-widget-wrapper" class="tp-widget-wrapper visible">
<div id="wrapper-company-stars" class="wrapper-company-stars">
<!-- Stars -->
<div id="tp-widget-stars" class="tp-widget-stars">
<div class="">
<div class="tp-stars tp-stars--0">
<div style="position: relative; height: 0; width: 100%;
padding: 0; padding-bottom: 18.326693227091635%;">
</div>
</div>
</div>
</div>
<div class="tp-widget-readmore" id="numberOfReviews"><strong>No
reviews</strong>
</div>
</div>
</div>
答案 0 :(得分:0)
从元素开始并找到父元素。
$('.tp-stars--0').parent('#tp-widget-wrapper').removeClass('visible');
答案 1 :(得分:0)
尝试在元素上使用each
循环并使用closest
获取父级。
$('.tp-widget-stars').find('.tp-stars.tp-stars--0').each(function() {
if ($(this).length) {
$(this).closest('#tp-widget-wrapper').removeClass('visible');
}
});