trigger() and triggerHandler() with 'click', trigger thickbox on page load

1.1k Views Asked by At

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?

3

There are 3 best solutions below

0
On BEST ANSWER

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

0
On

Try this as alternative:

$(document).ready(function(){
   window.location = $('#trigger-me').attr('href');
});
0
On

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");