The browser might navigate based on the href before the JavaScript in onclick gets executed. To prevent this, one can use event.preventDefault() within the click function.