Function on event click in jquery runs on pageload -
how come function run on pageload? see 4 alerts, if on page load each button 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 above function leadboard_switch_period(btn_id) { $("#leaderboard_nav a").removeclass("active_lb_btn"); alert("yes"); return false; }
also since i'm opening topic :) $("#leader_month_btn").on("click", leadboard_switch_period("#leader_month_btn"));
how can rewrite this, don't have write button id twice? this.id ?
you've missed function bit havn't you
$("#leader_all_time_btn").on("click", function() { leadboard_switch_period($(this)); });
Comments
Post a Comment