Chris Mendla
Chris Mendla

Reputation: 1017

cannot get an automatic jquery click

I am trying to set up a link that will be automatically clicked in order to refresh data every ten seconds.. For some reason I just can't seem to get the syntax correct.

If I have a link of

<a id="test123" data-remote="true" href="http://www.w3schools.com">test</a>

My script is

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
//<![CDATA[


    $(document).ready(
    function() {
    setInterval(function() {

       $("a#test123").click();

       $("a#test123").trigger("click");
          $("a#test123").after("testing");



        }, 10000);
        });

with the code above, 'testing' will appear after my link every ten seconds. However, the link does not execute. I think that means that my jquery, js and ID are correct. However, the link is not automatically clicking either on a test on w3schools 'try it' or when I put it into my page.

Upvotes: 1

Views: 46

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Try to invoke natural click of that anchor tag,

 $("a#test123")[0].click();

jQuery.click() and jQuery.trigger() will only invoke the event handler bound with the respective element, not the natural click.

Upvotes: 3

Related Questions