How to make onclick automatically through the onload function

I have a link href, and I would like it to be clicked when the page is loaded.

+5
source share
4 answers
$(document).ready(function() {
   $('#someLinkId').click();
});

or

$(document).ready(function() {
   $('#someLinkId').trigger("click");
});
+18
source
$(document).ready(function () {
   $("#myLink").trigger('click');
});

as you can read: http://docs.jquery.com/Events/trigger#eventdata

+3
source

$("#whateverid").trigger("click");

"whatid" - , .

+2

, ?

jQuery :

<body onload="window.location.replace('http://example.com/');">

<body onload="window.location.href = 'http://example.com/';">
+1

All Articles