Reputation: 19158
im trying to trigger a click event on a link on the page load. im currently working on this code here http://jsfiddle.net/QPPbA/
$(document).ready(function(){
$('#trigger-me').trigger('click');
});
<a href="http://www.stackoverflow.com" target="_blank" id="trigger-me">trigger hidden</a>
but it does not work. what im i missing here?
EDIT
I would like to trigger a thickbox on page load, i got some code but it only shows the black "tint".. so i thougth i would trigger it like this but this way does not work either.. any suggestions?
Upvotes: 0
Views: 1107
Reputation: 12240
Try this as alternative:
$(document).ready(function(){
window.location = $('#trigger-me').attr('href');
});
Upvotes: 0
Reputation: 344625
When you trigger an event with JavaScript, the browser's default action for that event isn't invoked. In this case, it won't cause a navigation when you trigger the click
event on a link.
If you want to redirect the visitor to another page, you can use window.location
:
window.location = $("#trigger-me").prop("href");
Upvotes: 0
Reputation: 10305
It hasn't got a click event...
$(document).ready(function(){
$('#trigger-me').click(function() {
window.location.href = $(this).attr("href");
});
$('#trigger-me').trigger('click');
});
update: jsfiddle
Upvotes: 1