Search code examples
javascriptjqueryjquery-pluginsunobtrusive-javascript

Applying javascript to a textbox unobtrusively


The title of the question is really vague and I am sorry for that.

What want to do is something like this (many third party libraries do that)

$( "#datepicker" ).datepicker();

I want to apply a function like datepicker() to a textbox. What the function does is not important, but how it is being applied like above is what I am trying to find out how to do.

Thanks.


Solution

  • (function($){
       $.fn.datepicker=function(){
          // do whatever you wanna do
          return this;
       }; 
    })(jQuery);
    

    allows you to do

    $('#datepicker').datepicker();