Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DEV

How to override JavaScript/jQuery functions and events?

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

. . .

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
IN THIS ARTICLE

Table of Content

Back to top