0

I have code like this

    $(document).on('click', '.addtocart .plus, .addtocart .minus', function () {
        var num = $('a.account span').text();
        .........
            .........
     });

Same code applies for

$(document).on('change','.addtocart .qty', function () {
        var num = $('a.account span').text();
        .........
            .........
 });

Can anyone tell me how to combine these click and change events?

1
  • Finally figure out it was the if/else?? check in your deleted question? Commented Jan 28, 2014 at 17:43

1 Answer 1

2

The simplest solution is to define a function

function f() {
     var num = $('a.account span').text();
     ...
}
$(document).on('click', '.addtocart .plus, .addtocart .minus', f)
.on('change','.addtocart .qty', f);

If you don't want to pollute the external namespace with this additional function, you may use an IIFE :

(function(){
  function f() {
     var num = $('a.account span').text();
     ...
  }
  $(document).on('click', '.addtocart .plus, .addtocart .minus', f)
  .on('change','.addtocart .qty', f);
})();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.