Using jQuery to programmatically click an <a> link
Solution 1:
Try this:
$('#myAnchor')[0].click();
It works for me.
Solution 2:
window.location = document.getElementById('myAnchor').href
Solution 3:
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...
$("#myAnchor").click(function(event)
{
var link = $(this);
var target = link.attr("target");
if($.trim(target).length > 0)
{
window.open(link.attr("href"), target);
}
else
{
window.location = link.attr("href");
}
event.preventDefault();
});
Solution 4:
<a href="#" id="myAnchor">Click me</a>
<script type="text/javascript">
$(document).ready(function(){
$('#myAnchor').click(function(){
window.location.href = 'index.php';
});
})
</script>