Answer the question
In order to leave comments, you need to log in
How do I change the style of only the hovered element in jQuery?
Hello, friends.
There is a code:
<div class="post-item">
<img src="img/1.jpg" alt="">
<div class="post-gradient"></div>
<div class="post-item_inner">
<h2><a href="#">Заголовок статьи</a></h2>
<div class="post-meta">
<div class="post-comment">
<i class="fa fa-commenting"></i>
<span class="comments-link">
<a href="#">5</a>
</span>
</div>
<div class="post-views">
<i class="fa fa-eye"></i>
<span class="comments-link">
<a href="#">2398</a>
</span>
</div>
</div>
</div>
</div>
$('.post-item').hover(
function(){
$('.post-gradient').css('background','linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.2) 70%)');
},
function(){
$('.post-gradient').css('background','linear-gradient(to top, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.2) 70%)');
}
);
Answer the question
In order to leave comments, you need to log in
$('.post-item').hover(
function() {
$(this).children('.post-gradient').css('background','linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.2) 70%)');
},
function() {
$(this).children('.post-gradient').css('background','linear-gradient(to top, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.2) 70%)');
}
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question