See the css written by you is not valid as in side {}
you can use css property but you cannot define any other element.
But yes there are some selector's in css like +
, ~
.
Suppose the html is like this
<ul>
<li>
<h2>...</h2>
</li>
</ul>
Then on hover of li you can do something in h2
by applying css for child div like this.
li:hover h2{
color:red;
}
A simple space defines that h2
is child element of <li>
.
Suppose html is like this
<ul>
<li>...</li>
<h2>...</h2>
</ul>
Then you can use this css to do something on h2
on li
hover
li:hover + h2{
color:red;
}
+
defines that h2
is placed next to li
These are some examples of using css for appyling something on different element.
But if this doesn't meets you requirement then the only solution is to use jquery. In jquery it doesn't matter where are the elements written you can simply do like this
$('li').hover(function(){
$('h2').css('color','red');
});
In above answer i am using <h2>
as a child of <ul>
just to give you example on the css rules but for valid html you can't use <h2>
as a direct child of <ul>
.