how to override the existing function in jquery

user2819086 picture user2819086 · Feb 17, 2014 · Viewed 27.4k times · Source

This is default for all js

getEditor: function(){
    $( '#datatableEditor' ).remove();
    var editor = $( '<div id="datatableEditor" class="popupEditor"/>' );
    $( 'body' ).prepend( editor );

    var dialog = $(editor).dialog({
        title: 'Edit item',
        modal: true,
        width: 'auto',
        height: 'auto'
    });

Now I am writing another js. I need to override the getEditor in my js...

Answer

Mehran Hatami picture Mehran Hatami · Feb 17, 2014

You haven't described your question, clearly but based on what you have mentioned in the title:

override the existing function in jquery

It seems you want to change a jQuery function and they usually are defined like $.fn.getEditor if it is the case, you should do:

(function ($) {
    var oldGetEditor = $.fn.getEditor;
    $.fn.getEditor = function() {

       //you can call the oldGetEditor here if you want
    };
})(jQuery);