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)

 

Leave a Reply