How to Create a JQuery Function

If you want to add JavaScript and/or JQuery functionality, and you want to easily reuse the codes in your future projects, it would be better to put in in a JQuery plugin. In other words, you will create a new JQuery plugin that you can reuse or share to other web developers. Also, putting your scripts inside a function will prevent conflicts with other scripts.

jQuery.fn.myfuncname = (function(param1, param2 /*, ... */){
// your codes here
});

To call your jQuery plugin, simply add the ff. line of codes

$('selector').myfuncname(1, 2)

 

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPrint this pageEmail this to someone

Leave a Reply

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