/ Published in: JavaScript
An example of how to extent the jQuery objects to include our own methods.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Pass an option hash as an argument to our function, and extend the jQuery object. * This is an example of how to extend the jQuery object. */ (function($){ $.fn.setReadOnly = function(readonly,ourOptions){ var options = $.extend({ read: 1.0, readOnly: 0.5 },ourOptions||{}); return this.filter('input:text').attr('readonly',readonly).css('opacity', readonly ? options.readOnly:options.read); }; })(jQuery); $(function(){ $('#same').click(function(){ var same = this.checked; $('#details2 input').setReadOnly(same,{readOnly: 0.1}); }); });