jQuery Object Hash and jQuery Extend


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.