Skip to content

Instantly share code, notes, and snippets.

@niwaringo
Created March 20, 2012 09:33
Show Gist options
  • Save niwaringo/2133379 to your computer and use it in GitHub Desktop.
Save niwaringo/2133379 to your computer and use it in GitHub Desktop.
第2引数でjQueryオブジェクトを返すjQueryプラグイン
/*
* 第2引数でjQueryオブジェクトを返すjQueryプラグイン
* $(selector).jeach(function(i, $e) {
* $e.text(); // $e -> jquery object
* this.tagName; // this -> dom elements
* ...
* });
*/
(function($) {
$.fn.jeach = function(callback) {
var jeach = function(object, callback) {
var i = 0,
length = object.length,
$object;
for ( ; i < length; ) {
$object = $(object[ i++ ]);
if (callback.call(object[ i ], i, $object) === false) {
break;
}
}
};
jeach(this, callback);
return this;
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment