We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

1man on 03/05/08


Tagged

jquery hash extend


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

korzhik


jQuery Object Hash and jQuery Extend


Published in: JavaScript 


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

  1. /**
  2.  * Pass an option hash as an argument to our function, and extend the jQuery object.
  3.  * This is an example of how to extend the jQuery object.
  4.  */
  5. (function($){
  6. $.fn.setReadOnly = function(readonly,ourOptions){
  7. var options = $.extend({
  8. read: 1.0,
  9. readOnly: 0.5
  10. },ourOptions||{});
  11. return this.filter('input:text').attr('readonly',readonly).css('opacity', readonly ? options.readOnly:options.read);
  12. };
  13. })(jQuery);
  14.  
  15. $(function(){
  16. $('#same').click(function(){
  17. var same = this.checked;
  18. $('#details2 input').setReadOnly(same,{readOnly: 0.1});
  19. });
  20. });

Report this snippet 

You need to login to post a comment.