:hover на другой блок(CSS и jQuery)
http://stackoverflow.com/questions/6910049/on-a-css-hover-event-can-i-change-another-divs-styling
==========================================================
you can do that, but only if
That's using the adjacent sibling combinator (
===========================================================
If there are other elements between
That's using the general sibling combinator (
===========================================================
With jquery you can quickly implement the behavior from your question:
707
0
==========================================================
you can do that, but only if
#b is after #a in the HTML.#a:hover + #b {
background: #ccc
}
<div id="a">Div A</div>
<div id="b">Div B</div>That's using the adjacent sibling combinator (
+).===========================================================
If there are other elements between
#a and #b#a:hover ~ #b {
background: #ccc
}
<div id="a">Div A</div>
<div>random other elements</div>
<div>random other elements</div>
<div>random other elements</div>
<div id="b">Div B</div>That's using the general sibling combinator (
~).===========================================================
With jquery you can quickly implement the behavior from your question:
$(function() {
$('#a').hover(function() {
$('#b').css('background-color', 'yellow');
}, function() {
// on mouseout, reset the background colour
$('#b').css('background-color', '');
});
});
Comments