I have a menu and each list item gets a different color border on hover. It works but it feels clunky. How can i optimize this code so I don't repeat so much.
$('ul>li:first-child>a').hover(function() {
$(this).css('border-bottom', '0.2em solid blue');
}, function() {
$(this).css('border-bottom', '0');
})
$('ul>li:nth-child(2)>a').hover(function() {
$(this).css('border-bottom', '0.2em solid green');
}, function() {
$(this).css('border-bottom', '0');
})
$('ul>li:last-child>a').hover(function() {
$(this).css('border-bottom', '0.2em solid yellow');
}, function() {
$(this).css('border-bottom', '0');
})
ul li {
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li><a href="#">Blue</a></li>
<li><a href="#">Green</a></li>
<li><a href="#">Yellow</a></li>
</ul>