Reading list Switch to dark mode

    How to override JavaScript/jQuery functions and events?

    Updated 16 July 2021

    Today with the help of this article I am going to explain you to override predefined functions and predefined events on a selector without changing in the core file.

    Override Event

    Below code snippet show that with the help of .off() function we can override events in jquery

    $(document).off('event', 'selector').on('event', 'selector', function() {
    	// Your code
    });

    override function

    Suppose you have a predefined js function helloWorld

    function helloWorld (argument) {
    	alert(argument);
    }

    Now, if you want to override this function then

    var origHelloWorld = window.helloWorld;
    window.helloWorld = function(argument) {
        	//your code
        	origHelloWorld(argument); 	// after your code if you want to call original function 
    }

    That’s all in this article, hope it will help you to override functions and events in js. Try this and if you have any query then just comment below. 🙂

    Start your headless eCommerce
    now.
    Find out More

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home

    Table of Content