0

Code:

<html>

<head>
  <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
</head>

<body>
  <a id="go" href="go">go</a>

  <script>
    $("#go").trigger("click");
  </script>
</body>

</html>

This script doesn't open the link go when visiting the page.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Alex01
  • 330
  • 3
  • 14

1 Answers1

1

.trigger("click") will trigger the bound event, but not the direct click.
In your case it will work:

go.click();
<a id="go" href="https://go" target="_blank">go</a>
imhvost
  • 4,750
  • 2
  • 8
  • 10