Dejan.S
Dejan.S

Reputation: 19158

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

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

Answers (3)

Christian P
Christian P

Reputation: 12240

Try this as alternative:

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

Upvotes: 0

Andy E
Andy E

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

Manuel van Rijn
Manuel van Rijn

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

Related Questions