I have a bit of a complicated problem.
There are two elements here:
(1). When selecting the $(".steps li")
I want the whole <li>
to change color to rgb(66, 81, 95)
. Then it has to change back to how it was before.
This part I have accomplished already, using .data()
.
The second part is the tricky part:
(2). When selecting an <a>
in the very same <li>
I want the color to stay the same and the underline to be applied. So I want the "World Assembly" text to stay green, be underlined, and have the rest of the <li>
be the white, inactivated color.
Is there a way to do this using callbacks in the hover function?
I need (1) and (2) to work at the same time.
I tired to hover on just the $(".steps li a") but that doesn't work because for the first part to work, the class has to be removed.
Anyway, I am unsure about this. Any advice would be appreciated.
Code is below:
CSS:
html, body {
background: #000;
color: #e7e7e7;
font-family:"Helvetica", "Arial", "Bitstream Vera Sans", "Verdana", sans-serif;
margin:0;
padding:0;
}
a {
color: rgb(66, 81, 95);
text-decoration:none;
}
a:hover {
/*color:#a0a0a0;*/
text-decoration:none;
}
.wa a {
color: rgb(68, 118, 67);
}
.steps {
width:400px;
margin:0 auto;
text-align:left;
line-height: 200%;
}
.steps a:hover {
text-decoration: underline;
}
.steps li:hover {
cursor: pointer;
color: rgb(66, 81, 95);
}
JQuery:
$(".steps li").hover(function () {
var the_class = $(this).children().attr("class");
$(this).data('class', the_class);
console.log(the_class);
$(this).children().toggleClass(the_class);
}, function () {
$(this).children().attr("class", $(this).data('class'));
});
Edit: I actually had to solve this using $.data()
twice, because in my locally hosted code I ended up having to add more anchor tags in the list, all with their own colors.
It now works like this:
$(".steps li").hover(function () {
var the_class = $(this).children().attr("class");
$(this).data('class', the_class);
$(this).children().toggleClass(the_class);
}, function () {
$(this).children().attr("class", $(this).data('class'));
});
$(".steps li a").hover(function(){
$(this).parent().parent().toggleClass('notHover');
$(this).parent().attr("class", $(this).parent().parent().data('class'));
}, function()
{
$(this).parent().parent().toggleClass('notHover');
$(this).parent().removeClass($(this).parent().parent().data('class'));
});
<li>
to change back to white when the<a>
is expressly hovered. – Gig<a>
hover would help then. Not on<li>
hover. Next time if you follow 'how to ask questions` providing an expected result will save lots of time and misunderstandings – Sammer:has()
, but it won't be available in CSS, only via the DOM. So this isn't possible with just CSS unfortunately, and it won't be, unless browsers include:has()
functionality w/ CSS. – Hako