Udders
Udders

Reputation: 6976

trigger/mimick click even on DOM ready

I ahve this jQuery that is called on click,

$("#overflow-cntr img").click(function(){
            $this = $(this);
            $("#bigpic-cntr canvas").remove();  
            $("#bigpic-cntr #bigpic").css("display", "block");
            window.setTimeout(function(){
                EFFECTS[$this.attr("id")]();
                }, 30);
        });

How would I trigger this on DOM ready instead of on click?

Upvotes: 0

Views: 89

Answers (2)

dougmacklin
dougmacklin

Reputation: 2610

Place the function inside $(document).ready() instead of click():

$(document).ready(function () {
    $this = $("#overflow-cntr img");
        $("#bigpic-cntr canvas").remove();  
        $("#bigpic-cntr #bigpic").css("display", "block");
        window.setTimeout(function(){
            EFFECTS[$this.attr("id")]();
            }, 30);
});

Upvotes: 0

lbstr
lbstr

Reputation: 2832

$(document).ready(function(){
    // bind the event and then trigger it immediately
    $("#overflow-cntr img").click(function(){
        $this = $(this);
        $("#bigpic-cntr canvas").remove();  
        $("#bigpic-cntr #bigpic").css("display", "block");
        window.setTimeout(function(){
            EFFECTS[$this.attr("id")]();
            }, 30);
    }).trigger('click');
});

Upvotes: 3

Related Questions