How is the onclick function return false not triggered in JavaScript?

according to the code typed out according to the part of javascript dom programming art about displaying pictures on a web page, there is a section that needs to enter onclick= "showPic (this); return false;" to prevent the page from popping up a new link to view the picture, but finally a new link pops up when it is run. The specific code is as follows:

< hr >
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8"/>
  <title>My Gallery</title>
</head>
<body>
  <h1>snapshots</h1>
  <ul>
    <li>
    <a href="images/do or die.jpg" onclick="showPic(this);return false;" title="do or die">DO</a>
    </li>
    <li>
    <a href="images/hand.jpg" onclick="showPic(this);return false;" title="hand">HAND</a>
    </li>
    <li>
    <a href="images/phrase.jpg" onclick="showPic(this);return false;" title="phrase">Phrase</a>
    </li>
  </ul>
  <img id="placeholder" src="images/dog.jpg" alt="My Gallery"/>
  <script>
  function showPic(whichpic)
  {var source=whichpic.getAttribute ("href");
  var placeholder=document.getElenmentById ("placeholder");
  placeholder.setAttribute("src",source);}
  </script>
</body>
</html>   
Mar.29,2021

first of all, your id acquisition words are misspelled. Secondly, the a tag href points to the problem and clicks the event.

< html lang= "en" >
< head >
< meta charset= "utf-8" / >
< title > My Gallery < / title >
< / head >
< body >
< H1 > snapshots < / H1 >

    <li>
    <a href="javascript:;" date-href="zhc1.jpg" onclick="showPic(this);return false;" title="do or die">DO</a>
    </li>
    <li>
    <a href="javascript:;" date-href="zhc2.jpg" onclick="showPic(this);return false;" title="hand">HAND</a>
    </li>
    <li>
    <a href="javascript:;" date-href="zhc3.jpg" onclick="showPic(this);return false;" title="phrase">Phrase</a>
    </li>


My Gallery
< script >

  function showPic(whichpic){
    var source=whichpic.getAttribute ("date-href");
    var placeholder=document.getElementById ("placeholder");
       placeholder.setAttribute("src",source);
}

< / script >
< / body >
< / html >


get id is document.getElementById ('')


I see here, too. Have you solved this problem?

Menu