When I click on the button on top of my website using a JavaScript the exact same second I press the button I get directly sent to the top of my website, how can I remove that and the same when closing the side nav.

 function openSlideMenu(){
  document.getElementById('side-menu').style.width = '250px';
  document.getElementById('main').style.marginLeft = '250px';       
}

function closeSlideMenu(){
  document.getElementById('side-menu').style.width = '0';
  document.getElementById('main').style.marginLeft = '0';
}

1 Answers

1
Andy Ray On

Your link has href="#" in it which sets an empty anchor on the page, jumping it to the top.

To prevent that behavior, prevent the default behavior on the onClick event.

 function openSlideMenu(event){
    event.preventDefault();