I am setting a value to input box and trigger to hear the change. I would also like to always hear the input change, and for that I made this function.

Can any expert please verify the way I did is correct? Or is it further tune-able?

var page = function () {
    return {
        init : function () {
            var input = $("#pNo");
            $(document).on("pageChange", this.onPageChange.bind(this));
            $(input).bind("change paste keyup",function() { $.event.trigger({type: "pageChange", element:input})});

        onPageChange : function (e) {


Live Demo


My suggestion is to reduce the code:

var page = {
  init: function(selector) {
    $(selector).on('change paste keyup', page.onPageChange);
  onPageChange: function(e) {

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.