How to run Click as page loading using jquery

I saw a lot of posts about this, but no one worked as I tried.

$(document).ready(function() {
   $('#link_to_content').tigger('click');
});

Once the page is loaded, I want to trigger a click. I know that it’s strange to open a link after the page loads, but in this case it makes sense.

I am using jquery 1.7

+5
source share
3 answers

it should be:

$(document).ready(function() {
   $('#link_to_content').trigger('click');
});

working example: http://jsfiddle.net/zpnQv/

EDIT:

if you want to follow the link, you can do something like:

HTML:
<a href="http://www.yahoo.com/" id="link_to_content">Click Me</a>


JS:
$(document).ready(function () {

    $("#link_to_content").click(function (e) {
        e.preventDefault();

        var href = $(this).attr("href");

        alert("going to " + href);
        window.location = href;
    });
    $('#link_to_content').trigger('click');
});

Example: http://jsbin.com/omudih/1/

+2
source

jQuery . , , , .

, , Javascript HtmlDOMElement .click().

: $('#link_to_content')[0].click();

+1

, , $(document).ready(). , , . setTimeout:

$("document").ready(function() {
setTimeout(function() {
    $("#link_to_content").trigger('click');
},10);
});

10 , $(document).ready().

.load();

.on() trigger()

$('div_to_load').load("#link_to_content",function(){
$("#link_to_content").trigger('click');
});

.on() example

$('div_to_click').on("click",".title",function(){
alert('sdfdsf');
});
0
source

All Articles