【发布时间】:2021-02-13 17:13:39
【问题描述】:
在我的 jQuery 代码(见下文)中,我无法更改“typetravaux”类内容的颜色。
悬停时的不透明度变化正常,但颜色变化不起作用(我尝试了 2 种不同的方法,但都不起作用)。
你们能告诉我我做错了什么吗?谢谢!
CSS:
.typetravaux {
width: 100%;
color: #ffffff;
}
HTML:
<div class="solutions">
<div class="bloc1">
<span class="typetravaux">PLOMBERIE</span>
<div class="picture"><img src="img/plomberie.png" class="prestapicture"></div>
</div>
<div class="bloc2">
<span class="typetravaux">CHAUFFAGE</span>
<div class="picture"><img src="img/chauffage.jpg" class="prestapicture"></div>
</div>
<div class="bloc3">
<span class="typetravaux">CLIMATISATION</span>
<div class="picture"><img src="img/climatisation.jpg" class="prestapicture"></div>
</div>
</div>
jQuery :
$prestapicture = $('.prestapicture');
for (y=0; y < $prestapicture.length; y++) {
$prestapicture.eq(y).on("mouseover", function() {
$(this).css("opacity", "0.3");
$(this).prev(".typetravaux").css("color","black") // **does not work**
})
$prestapicture.eq(y).on("mouseout", function() {
$(this).css("opacity", "1");
$(".typetravaux").eq(y).css("color","white"); //**does not work either**
})
}
【问题讨论】:
标签: jquery for-loop jquery-selectors