I know this question has been asked before, but after a search on the web I can't seem to find a straight forward answer.
the HTML
<a id=myAnchor href=index.php>
the jQuery (Both of these do not work)
$('#myAnchor').click();
or
$('#myAnchor').trigger('click');
What is the simplest and most efficient way to achieve this?
Add
onclick="window.location = this.href"
to your<a>
element. After this modification it could be.click()
ed with expected behaviour. To do so with every link on your page, you can add this:Click just triggers the click event / events not the actually "goto-the-links-href" action.
You have to write your own handler and then your $('#myAnchor').trigger('click'); will work...
Try this:
It works for me.
If you are using jQuery, you can do it with
jQuery.trigger
http://api.jquery.com/trigger/Example
I tried few of the above solutions but they didn't worked for me. Here is a link to the page which worked for me automatically click a link
Above link has many solutions and here's the one which worked for me,
Now within the
<script>
tags,Copy paste the above code and click on clicking the
'Magic button'
button, you will be redirected toErCafe.com
.