Sliding marker on link hover and click with jQuery

The code I'm bringing forward is for a vertical menu, where I needed a marker to do the following:

• When hovering over a link the marker should slide down next to it.

• When a link is clicked the marker should remain next to the clicked link, unless another link is being hovered over.

The code works, but it is redundant. How could I go about abstracting it?

I've already asked a similar question recently where I only had the "hover" part of the menu set up, and it was solved.

But I am a beginner in javascript and jQuery, and even though I've managed to understand the solution that was offered to me in the previous question, I am at a loss as to how to extrapolate that knowledge to abstracting this more convoluted code.

CODEPEN

HTML(Pug):

.staydown0#slide

p RED
p BLUE
p GREEN


CSS (Sass)

a
color: white
text-decoration: none

#slide
width: 10px
height: 30px
position: absolute
transition: 0.3s ease-in-out

#slide.staydown0
margin-top: 0px
background-color: red

#slide.staydown1
margin-top: 40px
background-color: blue

#slide.staydown2
margin-top: 80px
background-color: green

#slide.movedown0
margin-top: 0px
background-color: red

#slide.movedown1
margin-top: 40px
background-color: blue

#slide.movedown2
margin-top: 80px
background-color: green

margin-left: 30px

height: 40px
width: 70px
display: block

height: 30px
width: 70px
margin: 0px
display: flex
align-items: center
justify-content: center

background: red
background: blue
background: green



jQuery

$('#menulink1').hover( function(){$('#slide').addClass('movedown0');
},
function(){
$('#slide').removeClass('movedown0') });$('#menulink2').hover(
function(){
$('#slide').addClass('movedown1'); }, function(){$('#slide').removeClass('movedown1')

});

$('#menulink3').hover( function(){$('#slide').addClass('movedown2');
},
function(){
$('#slide').removeClass('movedown2') }); ///////$('#menulink1').on(
'click', function(){
$('#slide').addClass('staydown0').removeClass('staydown1 staydown2'); });$('#menulink2').on(
'click', function(){
$('#slide').addClass('staydown1').removeClass('staydown0 staydown2'); });$('#menulink3').on(
'click', function(){