Skip to content

Instantly share code, notes, and snippets.

@nenjiru
Created October 15, 2010 03:08
Show Gist options
  • Save nenjiru/627538 to your computer and use it in GitHub Desktop.
Save nenjiru/627538 to your computer and use it in GitHub Desktop.
ストライプテーブル jQuery Plugin
////////////////////////////////////////////////////////////////////////////////
// Add a classname to the alternate - jQuery Plugin
// 交互にクラス名を付与してストライプなテーブルを作成
//
// Copyright 2010, Minoru Nakanow
// Licensed under the MIT licenses.
// http://www.opensource.org/licenses/mit-license.html
//
// Usage:
// $("table").stripeTable();
//
////////////////////////////////////////////////////////////////////////////////
(function($) {
//--------------------------------------------------------------------------
// jQuery extend
//--------------------------------------------------------------------------
jQuery.fn.extend({
/**
* Stripe Table
*
* @param {String|Boolean} row 偶数行へのクラス名、falseでスキップ (初期値: "even")
* @param {String|Boolean} col 偶数列へのクラス名、falseでスキップ (初期値: "even")
* @return {jQuery}
*/
stripeTable: function(row, col) {
row = (row == undefined) ? "even" : row;
col = (col == undefined) ? "even" : col;
return this.each(function() {
$(this).find("tr:nth-child(even)").addClass(row)
.end().find("td:nth-child(even)").addClass(col);
});
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment