The most simple solution uses CSS
#my-panel:hover * {
background: gold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div id="my-panel" class="panel panel-primary" >
<div id="panel-header" class="panel-heading" >text</div>
<div id="panel-body" class="panel-body" >
<p >text</p>
</div>
</div>
The above code finds the panel we're looking for and attaches the pseudo-element :hover to it. It then finds all of its descendants with the universal selector, *.
You can also do it in jQuery. Listen for the mouseover and mouseout events as they represent when a mouse is hovering over and away from an element resepectively.
During the mouseover event, add a class for changing the background color. But because Bootstrap classes have styles already, you need to use the !important declaration. During the mouseout event, simply remove this class.
$(document).ready(function() {
$(".panel").on("mouseover", function() {
$(this).children().addClass("gold");
}).on("mouseout", function() {
$(this).children().removeClass("gold");
});
});
.gold { background: gold !important };
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="my-panel" class="panel panel-primary" >
<div id="panel-header" class="panel-heading" >text</div>
<div id="panel-body" class="panel-body" >
<p >text</p>
</div>
</div>
The JavaScript solution is similar to the jQuery one. Create variables for finding the body and header of the panel. You can listen for events either through inline events (ie onclick) or using addEventListener.
To add or remove classes, use the classList.add and classList.remove methods respectively.
var panel = document.getElementById("my-panel");
var panelHeader = document.getElementById("panel-header");
var panelBody = document.getElementById("panel-body");
panel.addEventListener("mouseover", function() {
panelHeader.classList.add("gold");
panelBody.classList.add("gold");
});
panel.addEventListener("mouseout", function() {
panelHeader.classList.remove("gold");
panelBody.classList.remove("gold");
});
.gold { background: gold !important };
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div id="my-panel" class="panel panel-primary" >
<div id="panel-header" class="panel-heading" >text</div>
<div id="panel-body" class="panel-body" >
<p >text</p>
</div>
</div>
Fiddles
CSS: http://jsfiddle.net/5v0osxce/
jQuery: http://jsfiddle.net/fehhemvo/
JavaScript: http://jsfiddle.net/t3mafrnr/1