How come function is run on pageload? I see 4 alerts, as if on page load each button is clicked once.
//Leaderboard switch alltime-week
$("#leader_all_time_btn").on("click", leadboard_switch_period("#leader_all_time_btn"));
$("#leader_month_btn").on("click", leadboard_switch_period("#leader_month_btn"));
$("#leader_week_btn").on("click", leadboard_switch_period("#leader_week_btn"));
$("#leader_day_btn").on("click", leadboard_switch_period("#leader_day_btn"));
//This is for above
function leadboard_switch_period(btn_id) {
$("#leaderboard_nav a").removeClass("active_lb_btn");
alert("yes");
return false;
}
Also since I'm opening a topic :)
$("#leader_month_btn").on("click", leadboard_switch_period("#leader_month_btn"));
how can I rewrite this, so that I don't have to write button id twice? this.id ?