javascript - Clicking on a link first time doesn't trigger jQuery, but clicking on it again triggers it twice -
so, i'm having bit of issue. have links when clicked run function in jquery, however, first time click link nothing happens. if click again, function runs twice, if click third time, runs 3 times off of click.
here jquery code
function updateentrystatus() { var anime_id = <?php echo $anime_id; ?>; var anime_list_entry_id = <?php echo $anime_list_entry_id; ?>; jquery('.wantedstatus').on('click', function(event) { var wantedstatus = jquery(this).text(); jquery.post("/wp-content/themes/sahifa/phanime_list/updatestatus_animelist.php", {firstparam : anime_id, secondparam : anime_list_entry_id, thirdparam : wantedstatus}, function(data) { //this response data serv console.log(data); jquery('#anime_list_update').html(data); }); return false; }); }
and here couple of links
<a href="javascript:void(0);" onclick="updateentrystatus();" class="wantedstatus">watching</a> | <a href="javascript:void(0);" onclick="updateentrystatus();" class="wantedstatus">plan watch</a> | <a href="javascript:void(0);" onclick="updateentrystatus();" class="wantedstatus">on hold</a> | <a href="javascript:void(0);" onclick="updateentrystatus();" class="wantedstatus">dropped</a>
example:
click 1: nothing happens
click 2: function runs twice.
click 3: function runs 3 times / in total runs 5 times.
click 4: function runs 4 times / in total run 9 times , on...
i assuming it's way i've setup click within function.
simply take
jquery('.wantedstatus').on('click', function(event) { var wantedstatus = jquery(this).text(); jquery.post("/wp-content/themes/sahifa/phanime_list/updatestatus_animelist.php", {firstparam : anime_id, secondparam : anime_list_entry_id, thirdparam : wantedstatus}, function(data) { //this response data serv console.log(data); jquery('#anime_list_update').html(data); }); return false; }); }
part out of updateentrystatus() function.
Comments
Post a Comment