【发布时间】:2019-03-12 04:29:38
【问题描述】:
我在一个网站上工作,我想检查元素中是否有任何内容。
以下是我的 html 代码。我已经提到了 condition#1,如果 featured-block__title 和 featured-block__tag 类中有内容,则应该通过脚本添加 opacity-pointseven 类。
<div class="featured-block">
<a href="/" class="featured-block__item cf">
<div class="featured-block__item-inner">
<figure class="featured-block__image img-fit">
<img src=""> // (condition#1, where opacity-pointseven needs to be added)
</figure>
<div class="featured-block__content">
<h1 style="margin-bottom:0px;" class="featured-block__title">Trans Mountain Pipeline: NEB Releases New Report, Recommends Approval </h1>
<h1 class="featured-block__tag"> More Coverage</h1>
</div>
</div>
</a>
</div>
问题陈述:
我尝试了以下方式,但似乎无法正常工作。
<script>
jQuery(function ($) {
if ($(this).find(".featured-block__title").not(":empty") && $(this).find(".featured-block__tag").not(":empty")) {
$(this).find(".img-fit img").addClass("opacity-pointseven"); // For condition#1
}
});
})
</script>
【问题讨论】:
标签: javascript jquery html class