javascript - How an event (click) can be triggered again and again by another click -


final edit

the solution framework (drupal) solution using drupal behavior attachment : https://drupal.org/node/756722#behaviors instead of jquery. here attached triggered action on widget.

-----

context description: users can vote several times on 1 or more projects in limit of xx number of votes. everytime vote, i'd trigger refresh button update block showing votes aggregated in table. block reload list in table using ajax function , part works great.

unfortunately me, function below working once. after first click triggers refresh button, next "a.vote" clicks made user don't trigger refresh anymore.

function refreshtable(){ $("a.vote").click(function(){     $(".refresh-button").trigger("click");     //missing here saying: again , again far user clicks;     }); }; $(document).ready(refreshtable); 

my question: how can improve function make triggering happens again , again?

edit : here code of first button supposed trigger second 1 :

$('.plus1-widget', context).once('plus1', function(){     var plus1_widget = $(this);     plus1_widget.find('.plus1-link').attr('href', function(){ return $(this).attr('href') + '&json=true'; }).click(function(){       $.getjson($(this).attr('href'), function(json){         if (json) {           var newwidget = $(json.widget);           newwidget.hide();           plus1_widget.replacewith(newwidget);           newwidget.fadein('slow');           drupal.attachbehaviors();         }       });       return false;     });   }); 

there this: plus1_widget.replacewith(newwidget), @chad , @jasonp suggested may related document.ready implicates function triggered once, when document ready, right?
after function triggered, document still ready, , maybe should ready again instead. not sure right. please me understand this.

my guess a.vote element bound event gets replaced when refresh html, causing handler lost. try event delegation:

$(document).on('click', 'a.vote', function() {     $(".refresh-button").click(); }); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -