w1l
w1l

Reputation: 157

Javascript, load onclick at pageload, whats broken?

I'm a dizzy designer. I can't can't see why this isn't working:

 <head>
 <script type="text/javascript">
      $().ready(function() {
           $('#test').trigger("click");
      });
 </script>  
 </head>
 <body>
      <a id="test" href="http://www.dartworks.net" >click here</a>
</body>

what am i doing wrong?

Upvotes: 0

Views: 471

Answers (2)

Muhamad Bhaa Asfour
Muhamad Bhaa Asfour

Reputation: 1035

you didn't attach any click event to the <a> tag you just output it as a link

use the window.location.href like this :

$(document).ready(function() {
    window.location.href = "http://www.dartworks.net";
});

Upvotes: 1

Quentin
Quentin

Reputation: 943979

The trigger method will fire all the event handlers bound to that event. Following the link is default behaviour, not something caused by a DOM event handler.

Upvotes: 1

Related Questions