jQuery Event How to - Simulate click on html anchor tag








Question

We would like to know how to simulate click on html anchor tag.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){<!--from w w w . jav a2  s  .co m-->
    $('a').get(0).click();
});//]]>  
</script>
</head>
<body>
  <a href="http://java2s.com"> Download this pic </a>
</body>
</html>

The code above is rendered as follows: