Skip to content

Instantly share code, notes, and snippets.

@ephemeralsnow
Created September 26, 2013 06:55
Show Gist options
  • Save ephemeralsnow/6710697 to your computer and use it in GitHub Desktop.
Save ephemeralsnow/6710697 to your computer and use it in GitHub Desktop.
jQueryで var $id1 = $("#id1"), $id2 = $("#id2"); と変数にキャッシュし、 toTraversable($id1, $id2).css("color", "red"); と書きたかった。
var toTraversable = function(args) {
var $result = $();
$(arguments).each(function() {
var $this = $(this);
if ($this.length > 1) {
$this.each(function() {
$.merge($result, toTraversable(this));
});
} else {
$.merge($result, $this);
}
});
return $result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment