Html <a> activate on click or enter pressed - Javascript jQuery

Javascript examples for jQuery:Link

Description

Html <a> activate on click or enter pressed

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.8.3.js"></script> 
 </head> //from w w  w.j a  v a 2  s  .c om
 <body> 
  <a href="#" onclick="dosomething()" id="Enter">ClickMe</a> 
  <script type="text/javascript">
$(document).keypress(function(event){
    if(event.keyCode == 13){
        $("#Enter").click();
    }
});
function dosomething(){
    console.log('hi');
}

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

Related Tutorials