Created
October 19, 2011 21:03
-
-
Save glesica/1299668 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mutifunctional method to get and set values to a collection | |
// The value/s can optionally be executed if it's a function | |
access: function( elems, key, value, exec, fn, pass ) { | |
var length = elems.length; | |
// Setting many attributes | |
if ( typeof key === "object" ) { | |
for ( var k in key ) { | |
jQuery.access( elems, k, key[k], exec, fn, value ); | |
} | |
return elems; | |
} | |
// Setting one attribute | |
if ( value !== undefined ) { | |
// Optionally, function values get executed if exec is true | |
exec = !pass && exec && jQuery.isFunction(value); | |
for ( var i = 0; i < length; i++ ) { | |
fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass ); | |
} | |
return elems; | |
} | |
// Getting an attribute | |
return length ? fn( elems[0], key ) : undefined; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment