What I want to do is to change the default jquery method of a specific element.
For example, I want to change the method val()
of some (not all) select
list. And after that revert back if necessary.
My first attempt is the following but not work.
$('#list').val = function(){ alert('toto'); };
//and then
$('#list').val() //not work
SOLUTION
var old_val = $.fn.val;
$.fn.val = function(value){
//some condition to trigger
if (this.hasClass('someclass')){
//getter
if (value===undefined){
//do something to get the values
return val;
}
//setter
else {
//do something with the value
return this;
}
}
return old_val.apply(this, arguments);
};