Definitely, but I will not recommend it if you really do not want to do some crazy science on the page (for example, add some custom proxies to interfere with code that you cannot control). Instead, you can create your own function by adding it to the object $.fn(see below).
Override
, , : $.fn.val:
var $input = $("input")
console.log($input.val())
const oldValFn = $.fn.val
$.fn.val = function () {
console.log("Called val");
return oldValFn.apply(this, arguments);
};
console.log($input.val())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input value="42" />
val ( , ):
var $input = $("input")
$.fn.customVal = function () {
var value = this.val();
value = "The value is: " + value
return value;
};
console.log($input.customVal())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input value="42" />