Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created December 14, 2009 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliocesar/255851 to your computer and use it in GitHub Desktop.
Save juliocesar/255851 to your computer and use it in GitHub Desktop.
// Say we got: <ul> <li>Foo</li> <li>Bar</li> </ul>
// Fade list entries one by one, with a 200ms interval
//
// $.withChildren('ul:first', 'li', 'fadeOut', [], 200)
//
;(function($) {
$.withChildren = function(element, childSelector, _method, args, after) {
var childTag = childSelector || {'DIV': 'div', 'UL': 'li'}[$(element).get(0).tagName] || 'div';
var children = $(element).find('> ' + childTag);
(function(e) {
$(e)[_method].apply($(e), args);
var self = arguments.callee;
if ($(e).next().length) { setTimeout(function() { self($(e).next()); }, (parseInt(after) || 1000)); };
})(children[0]);
};
})(jQuery);
// *cough* documentation:
// $.withChildren(<selector for finding child nodes>, <method called on children>, <arguments for method>, <interval>)
//
// Pluginize it
$.fn.withChildren = function(childSelector, _method, args, after) {
return this.each(function() { $.withChildren(this, childSelector, _method, args, after) });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment