I have written below code and 2 problem: 1) I want when cursor hover on my div with details class, color changed for whole div but in my code on internal div doesn't do that. 2) also the jquery lines written for all div almost is the same, and I have a lot of these div. can I write my code brief for avoid repeating?
Please can you tell me how to do this!
$(".detail-1").hover(function() {
$(".detail-1 div:first-child").css("background-color", "green");
$(".detail-1 div:nth-child(2) p").css("color", "blue");
})
$(".detail-1").mouseout(function() {
$(".detail-1 div:first-child").css("background-color", "#41b5e7");
$(".detail-1 div:nth-child(2) p").css("color", "black");
})
$(".detail-2").hover(function() {
$(".detail-2 div:first-child").css("background-color", "yellow");
$(".detail-2 div:nth-child(2) p").css("color", "blue");
})
$(".detail-2").mouseout(function() {
$(".detail-2 div:first-child").css("background-color", "#41b5e7");
$(".detail-2 div:nth-child(2) p").css("color", "black");
})
$(".detail-3").hover(function() {
$(".detail-3 div:first-child").css("background-color", "pink");
$(".detail-3 div:nth-child(2) p").css("color", "blue");
})
$(".detail-3").mouseout(function() {
$(".detail-3 div:first-child").css("background-color", "#41b5e7");
$(".detail-3 div:nth-child(2) p").css("color", "black");
})
.details {
width: 200px;
height: 90px;
border: 1px solid #333;
margin-top: 10px;
}
.details > div {
float: left;
}
.details > div > p {
line-height: 15px;
padding-left: 10px;
}
.details div:first-child {
width: 70px;
height: 70px;
background-color: #41b5e7;
margin: 10px 0px 0px 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="details detail-1" data-number="1">
<div>
</div>
<div>
<p>text-1</p>
<P>Description-1</P>
</div>
</div>
<div class="details detail-2" data-number="2">
<div>
</div>
<div>
<p>text-2</p>
<P>Description-2</P>
</div>
</div>
<div class="details detail-3" data-number="3">
<div>
</div>
<div>
<p>text-3</p>
<P>Description-3</P>
</div>
</div>