Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to override the existing function in jquery [duplicate]

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...

like image 227
user2819086 Avatar asked Jan 11 '23 04:01

user2819086


1 Answers

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);
like image 199
Mehran Hatami Avatar answered Feb 01 '23 02:02

Mehran Hatami