Return to Snippet

Revision: 5376
at March 5, 2008 06:03 by 1man


Initial Code
/**
 * 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});
	});
});

Initial URL

                                

Initial Description
An example of how to extent the jQuery objects to include our own methods.

Initial Title
jQuery Object Hash and jQuery Extend

Initial Tags
jquery

Initial Language
JavaScript