Skip to content

Instantly share code, notes, and snippets.

@hanigamal
Created June 15, 2013 12:37
Show Gist options
  • Save hanigamal/5787987 to your computer and use it in GitHub Desktop.
Save hanigamal/5787987 to your computer and use it in GitHub Desktop.
jquery simple math
(function ($) {
'use strict';
$.fn.math = function (operation, a, b) {
return this.each(function () {
var result = 0;
switch(operation){
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a * b;
break;
case '/':
if(b !== 0){
result = a / b;
} else {
result = "undefined";
}
break;
}
}
$(this).html(result);
});
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment