If all you're trying to do is switch back and forth between a positive/negative number you can make your code much simpler and lose all the if
conditions:
$('.switch').click(function () {
var $input = $('#myInput');
$input.val() != "" && !isNaN($input.val()) && $input.val(-$input.val());
});
This is the equivalent of multiplying the number by -1
, which will have the same effect.