Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Himanshu Chopra
3,055 PointsChanging hover styles with Javascript?
Hi I have this code in my CSS file
.topnav > li:hover:not(.active) > a {
background: #3e3e3e;
}
I want to achieve this with javascript . Could someone please help me with this thing, with some explanation ?
1 Answer
Liam Maclachlan
22,805 PointsI think, from what you are trying to achieve, if you overwrite the '.active' css below the ':hover', you won't have the problem that I think you are having :)
.topnav li.active > a {
background: #ffb900;
}
.topnav > li:hover > a {
background: #3e3e3e;
}
.topnav > li.active:hover > a {
background: #ffb900;
}
Liam Maclachlan
22,805 PointsThis is making an assumption, though. If you still want a jQuery/Javascript, I'm happy to provide an answer :)
Himanshu Chopra
3,055 PointsHello Liam Maclachlan . Yes jQuery would be suffice. Well I am working on theme customization where User have some option to customize the theme. The user can change the background Color or Header and Side Navigation , He has the option to change the color of Icons.
Now I have done these things but I want that user can also change the Background Color of the Option in header for hover state. I want to target this.
.topnav > li:hover:not(.active) > a
or
.topnav > li:hover > a
& then I will set the color picked by user to this selector.
Liam Maclachlan
22,805 PointsLiam Maclachlan
22,805 PointsWould jQuery suffice, or does it need to be JavaScript? This would be much easier using the jQuery library, is all :)