jQuery:将类添加到Element的Child

Aar*_*ron 3 html css jquery

HTML:

<div class="cell-container">
  <img src="image.png" class="thumbnail" />
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.hover {
  background-color: silver;
}
.hover-image {
  border: 1px solid #000;
}
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$(".cell-container").mouseover(function() {
    $(this).addClass("hover");
});

$(".cell-container").mouseout(function() {
    $(this).removeClass("hover");
});
Run Code Online (Sandbox Code Playgroud)

基本上我希望div cell-container有一个突出显示的背景onmouseover.但也要在其中添加边框<img>.我怎样才能做到这一点?

Ale*_*s G 7

为什么不在CSS中这样做呢?

div.cell-container:hover {
  background-color: silver;
}

div.cell-container:hover img.thumbnail {
  border: 1px solid #000;
}
Run Code Online (Sandbox Code Playgroud)