Reputation: 914
I have an click() function that should trigger when the page loads. but it doesn't - only when you manually click it.
Here is the fiddle: http://jsfiddle.net/serw5/
//onload:
$(".pageselector").first().trigger('click');
$(".pageselector").click(function(e){
e.preventDefault();
var pageid = $(this).data('pageid');
alert(pageid);
// ajax....
});
Thanks in advance
Upvotes: 0
Views: 1843
Reputation: 1144
You need to be put your trigger
call after you bind the click handler. Right now, you are trying to trigger a non-existent click handler.
Upvotes: 5
Reputation: 104775
Put the trigger
call after your handler declaration:
$(".pageselector").click(function(e){
e.preventDefault();
var pageid = $(this).data('pageid');
alert(pageid);
// ajax....
});
$(".pageselector").first().trigger('click');
Fiddle: http://jsfiddle.net/serw5/1/
Upvotes: 2