show alert/console log message on hyperlink click - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

show alert/console log message on hyperlink click

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function getVal(fid) {//from   w  w  w  .j  a  v a2s.  c  o m
    if (fid != null && fid != undefined && fid != "")
        console.log('hi')
    else 
        console.log("else!");
}

      </script> 
   </head> 
   <body> 
      <a href="##" onclick="getVal();">test</a> 
      <a href="##" onclick="getVal(2134);">test</a> 
      <a href="##" onclick="getVal('2234');">test</a>  
   </body>
</html>

Related Tutorials