1

Basically i want to call click event as soon as the document is loaded. Below is the sample code.

<!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
            $("a").trigger("click");
     });

    </script>
    </head>
    <body>

    <a href="http://google.com/">Link</a>

    </body>
    </html>

2 Answers2

0

You need to navigate using href of anchor and here is why:

window.location =  $("a").attr('href');
Community
  • 1
  • 1
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0
    <!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
 <script>
jQuery(document).ready(function(){
jQuery( "a" ).on( "click", function() {

 window.open('http://www.google.com');
});
jQuery( "a" ).trigger( "click" );
});
</script>
</head>
<body>
<a href="#">Link</a>
</body>
</html>
Samyappa
  • 535
  • 2
  • 11