Return to Snippet

Revision: 27398
at June 5, 2010 11:29 by minky


Initial Code
/*
 * @package pwToggleAttr
 * @description toggles an attribute of an element on click
 * @author Jared Clarke <[email protected]>
 * @copyright 2010 (c) Jared Clarke @ pixaweb.co.uk
 * @version 0.1
 */
(function ($) {

    $.fn.pwToggleAttr = function (options) {
    
        var opts = $.extend({}, $.fn.pwToggleAttr.defaults, options);
        
        return this.each(function () {
        
            var _this   = $(this),
                _target = (opts.target == false) ? _this : $(opts.target);
            
            _this.click( function (event) {
            
                event.preventDefault();
            
                _target.attr(opts.attr, !_target.attr(opts.attr));
                
            });
            
            return _this;
            
        });
        
    };
    
    $.fn.pwToggleAttr.defaults = {
        target  : false,
        attr    : "disabled"
    };
    
})(jQuery);

Initial URL
http://www.pixaweb.co.uk/resources?tag=jquery

Initial Description
## PWToggleAttr

This jQuery Plugin allows you to toggle an attribute on/off on an element. e.g. the disabled element of an input. Examples and such are available on http://www.pixaweb.co.uk/resources

Initial Title
PWToggleAttr - A jQuery Attribute Toggle Plugin

Initial Tags
jquery

Initial Language
jQuery