Return false cannot prevent onclick from jumping after binding an event to it in JavaScript

this question means to change the placeholder of img by clicking on the a link, but add the onclick event in HTML and return false still appears the page jump situation, also according to the night check but did not find any problems, please take a look! Here is the code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Image Gallery</title>
  
</head>
<body>
  <h1>Snapshots</h1>
  <ul>
    <li>
      <a href="images/fireworks.jpg" title="A fireworks display" onclick="showPic(this);return false">Fireworks</a>
    </li>
    <li>
      <a href="images/coffee.jpg" title="A cup of black coffee" onclick="showPic(this);return false;">Coffee</a>
    </li>
    <li>
      <a href="images/rose.jpg" title="A red, red rose" onclick="showPic(this);renturn false;">Rose</a>
    </li>
    <li>
      <a href="images/bigben.jpg" title="The famous clock" onclick="showPic(this);return false;">Big Ben</a>
    </li>
  </ul>
  <img id="placeholder" src=" " alt="my imgage gallery">
  <p id="description">Choose an image.

</body> <script> function showPic ( whichpic){ var source = whichpic.getAttibute("href"); var placeholder = document.getElementById( "placeholder"); placeholder.setAttribute( "src",source); var text = whichpic.getAttibute( "title" ); var description = document.getElementById("description"); description.firstChild.nodeValue = text; } function countBodyChildren(){ var body_element = document.getElementsByTagName( "body")[0]; console.log ( body_element.childNodes.length); } window.onload = countBodyChildren; </script> </html>
Jul.30,2021

this should be divided into non-ie and ie. You have to see which browser is the first. Secondly, in order to prevent the default event, you can try preventdefault

.
Menu