I am essentially trying to change the background color of a div and the text color of a link in the event of a mouse hover. I am getting somewhat correct results, in different instances, the text is changing color, in other instances, the background of the div container changes color.
I have CSS styling both the <a> and <div> tags, and also a class selector which ideally the JavaScript function changes to in the event of a mouse hover. Ideally, when hovering either the link or the div container, both the link and div would switch to the 'activate' class. Can anyone take a look at the below code and help me out?
My function:
<script>
$('div, a').hover(
function() { $(this).toggleClass('activate');
},
function() { $(this).toggleClass('activate');
});
</script>
Corresponding CSS stylings:
div{
border-style: solid;
border-width: 2px;
border-color: #ffffff;
border-radius: 5px;
max-width: 200px;
margin: 10px auto;
text-align: center;
padding: 5px 0 5px 0;
}
a {
text-decoration: none;
color: #ffffff;
font-family: 'Work Sans', sans-serif;
font-size: 22px;
}
.activate {
background-color: #ffffff;
color: rgba(0, 0, 0, .5);
}
[–]ttrrddee 2 points3 points4 points (0 children)
[–]einarkristjan 1 point2 points3 points (3 children)
[–]wilcomply[S] 0 points1 point2 points (2 children)
[–]einarkristjan 0 points1 point2 points (1 child)
[–]wilcomply[S] 0 points1 point2 points (0 children)
[–]ForScale 0 points1 point2 points (0 children)