因此,我有幾個文章標籤,每個鏈接都有一個鏈接,當它需要更改包含該文章內圖像的div的背景時。我希望鏈接懸停只適用於它所在的文章,而不會影響其他文章。下面的代碼似乎也是針對其他文章的div。請有人指出我正確的方向?非常感謝當鼠標懸停在鏈接上時,改變div的顏色
$(".edgtf-pli-link").on("hover", function() {
$(".edgtf-pli-image").css("background", "red");
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<article class="edgtf-pl-item post-36">
<div class="edgtf-pl-item-inner">
<div class="edgtf-pli-image">
<img width="80" height="106" src="garden-featured.jpg" />
</div>
<div class="edgtf-pli-text-holder">
<div class="edgtf-pli-text-wrapper">
<div class="edgtf-pli-text">
<h4 itemprop="name" class="edgtf-pli-title entry-title">Garden</h4>
<p itemprop="description" class="edgtf-pli-excerpt"></p>
</div>
</div>
</div>
<a itemprop="url" class="edgtf-pli-link" href="http://localhost:8888/" target="_self"></a>
</div>
</article>
<article class="edgtf-pl-item post-37">
<div class="edgtf-pl-item-inner">
<div class="edgtf-pli-image">
<img width="80" height="106" src="wall-featured.jpg" />
</div>
<div class="edgtf-pli-text-holder">
<div class="edgtf-pli-text-wrapper">
<div class="edgtf-pli-text">
<h4 itemprop="name" class="edgtf-pli-title entry-title">Wall</h4>
<p itemprop="description" class="edgtf-pli-excerpt"></p>
</div>
</div>
</div>
<a itemprop="url" class="edgtf-pli-link" href="http://localhost:8888" target="_self"></a>
</div>
</article>
嘗試'$(this).find('。edgtf-pli-image')。css(「background」,「red」);'而不是 – Toxide82
你介意去除水平滾動條嗎?這會提高可讀性。 – reporter