0

As soon as the page load, href link should get trigger(Manual click should not happen).Plz help

<a href="www.google.com" id="info">Information</a>

<script>
$(document).ready(function(){
  $("#info").click(function(){

  });
  $(window).load(function(){
    $("#info").trigger("click");
  });
});
</script>
user2721624
  • 43
  • 1
  • 2
  • 8
  • First I'm not sure the window load event fires when inside a document ready event. Second, I'm unsure if the click event is defined for a link. If you fleshed out the click handler you're adding to it you could trigger it. Better yet, `window.location.href="www.google.com";` – Clint Powell Feb 11 '14 at 08:17
  • And this is duplicate of http://stackoverflow.com/questions/5811122/how-to-trigger-a-click-on-a-link-using-jquery – Clint Powell Feb 11 '14 at 08:27
  • Manual click should not happen – user2721624 Feb 11 '14 at 09:21

6 Answers6

1

Trigger the event as follows

<a href="www.google.com" id="info">Information</a>

<script>
$(document).ready(function(){
     $("#info").click(function(){
         alert('clicked');
     }).trigger("click");
});
</script>
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
0

You do not need empty click handler for anchor. Just use:

<script>
$(document).ready(function(){
  $("#info").trigger("click");
});
</script>
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

Rewrite:

$(document).ready(function(){
  $("#info").click(function(){
    alert()
  });
  $("#info").click()
});
Farkhat Mikhalko
  • 3,565
  • 3
  • 23
  • 37
0

How about just redirecting with JQuery?

<script>
   $(document).ready(function(){
      window.location.href = "http://www.google.com";
   });
</script>
Dumisani
  • 2,988
  • 1
  • 29
  • 40
0

Use this

    <script>
    $(document).ready(function(){
    $("#info").on("click",function(){
      var url = $(this).attr('href');
       $(location).attr('href',url);
    });
    $("#info").trigger("click");
    });
    </script>

Jsffidle demo http://jsfiddle.net/waseemmachloy/tBGX3/2/

tevanraj
  • 565
  • 5
  • 12
Dexture
  • 976
  • 1
  • 11
  • 29
0

Simply

$(function(){
  $("#info")[0].click();
});
Clint Powell
  • 2,368
  • 2
  • 16
  • 19