Saturday, 30 June 2012

JQuery $.on() function and the 'click' handler

So I am using the $.on() function to assign the 'click' event to one of my buttons, and on certain browsers things worked well, but on Firefox there was a problem, specifically the button would refresh.
My original code:


      self.init = function() { 
           $('.search-btn').on('click', function() {
                var searchTerm = $('#searchTerm').val();
                self.doSearch(searchTerm);
           });
      };  


It turns out it was a mistake I made by not returning a value from the annoymous function, so it would stop flow of execution.



      self.init = function() { 
           $('.search-btn').on('click', function() {
                var searchTerm = $('#searchTerm').val();
                self.doSearch(searchTerm);
                return false;
           });
      };  


No comments:

Post a Comment