Reputation: 6976
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
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
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