Free Business Consulting

How to create callback functions for jQuery plugins & extensions?


Jul092012
blog-image
adminjQueryPHP13 Comments

Most of the time custom jQuery plugins and extensions that we create do not use callback functions. They usually simply work on DOM elements or do some calculations. But there are cases when we need to define our own custom callback functions for our plugins.And this is especially true when our plugins utilize AJAX querying.

Let’s say our custom jQuery extension gets data by making some AJAX request.

What is bad in this jQuery code is that the callback function is defined and hard-coded right in the plugin itself. The plugin is not really flexible and its user will have to change the plugin code, which is bad!

So the solution is to define your own custom callback function argument. Here is how it is done:

The above code shows you how to create a callback function for AJAX load, but if you want to create a simple callback function for your jQuery plugin, for example, the one that executes on your own custom events. To achieve this you can do the following:

Leave a Reply

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

Get News In Your Inbox

Popular Blogs

recent-blog-image
How to create callback functions for jQuery plugins & extensions?

Most of the time custom jQuery plugins and extensions that we create do not use callback functions. They usually simply work on DOM elements or do some calculations. But there…

Continue Reading
recent-blog-image
Top 5 Best Ecommerce plugins in WordPress

Nowadays online shopping has increased and become very convenient shopping place for users, you may be wanting to start your own online shop so you can unleash your products to…

Continue Reading
recent-blog-image
10 Best WordPress Live Chat Plugins for Customer Support

The Live chat is the common thing now days, if you own any eCommerce website or if you are the service provider. It makes easy for your customers to contact…

Continue Reading
recent-blog-image
Free plagiarism checker sites

Plagiarism is the process of taking someone’s ideas & work and passing them off as one’s own. Prevent Plagiarism to check originality of content is the most important factor for…

Continue Reading
recent-blog-image
How to show wordpress posts in other CMS?

Currently since from few weeks, I am working on Expression Engine. Now you thought that what is Expression Engine. Now let me explain you in little brief. Expression Engine is…

Continue Reading

Remarkable Facts About Us

0 %
Client satisfaction
0 +
Years of Experience
0 +
Happy Clients
+
Projects Accomplished

Ready to Get Started ?