リスト11. フィルタ(基本)
// 基本フィルタの実行
function Sample11(sw){
jQuery('#sample11 *').css('background-color','');
switch( sw ){
// 最初のtd要素
case ':first':
jQuery('#sample11 td:first').css('background-color','skyblue');
break;
// 最後のtd要素
case ':last':
jQuery('#sample11 td:last').css('background-color','skyblue');
break;
// #tr2を除くのtr要素
case ':not':
jQuery('#sample11 tr:not(#tr2)').css('background-color','skyblue');
break;
// 奇数行(最初は0行)
case ':odd':
jQuery('#sample11 tr:odd').css('background-color','skyblue');
break;
// 偶数行(最初は0行)
case ':even':
jQuery('#sample11 tr:even').css('background-color','skyblue');
break;
// 5番目のtd要素(0から始まるので、index=4)
case ':eq':
jQuery('#sample11 td:eq(4)').css('background-color','skyblue');
break;
// 5番目より前のtd要素(0から始まるので、index=4)
case ':lt':
jQuery('#sample11 td:lt(4)').css('background-color','skyblue');
break;
// 5番目より後のtd要素(0から始まるので、index=4)
case ':gt':
jQuery('#sample11 td:gt(4)').css('background-color','skyblue');
break;
// 「番目」を持つtd要素
case ':contains':
jQuery('#sample11 td:contains(番目)').css('background-color','skyblue');
break;
// 空のtd要素
case ':empty':
jQuery('#sample11 td:empty').css('background-color','skyblue');
break;
// 要素を持つtd要素
case ':has':
jQuery('#sample11 td:has(*)').css('background-color','skyblue');
break;
// b要素の親要素
case ':parent':
jQuery('#sample11 b:parent').css('background-color','skyblue');
break;
// 隠し要素
case ':hidden':
hiddenTR = jQuery('#sample11 *:hidden');
hiddenTR.show();
break;
// 可視要素
case ':visible':
jQuery('#sample11 td:visible').css('background-color','skyblue');
break;
// 各行2番目の子要素
case ':nth-child(index)':
jQuery('#sample11 td:nth-child(2)').css('background-color','skyblue');
break;
// 各行奇数番目の子要素
case ':nth-child(odd)':
jQuery('#sample11 td:nth-child(odd)').css('background-color','skyblue');
break;
// 各行偶数番目の子要素
case ':nth-child(even)':
jQuery('#sample11 td:nth-child(even)').css('background-color','skyblue');
break;
// 各行3n番目の子要素
case ':nth-child(equation)':
jQuery('#sample11 td:nth-child(3n)').css('background-color','skyblue');
break;
// 各行最初の子要素
case ':first-child':
jQuery('#sample11 th:first-child').css('background-color','skyblue');
break;
// 各行最後の子要素
case ':last-child':
jQuery('#sample11 td:last-child').css('background-color','skyblue');
break;
// 各行一つしかない子要素
case ':last-child':
jQuery('#sample11 th:only-child').css('background-color','skyblue');
break;
// 初期化
default:
try{
hiddenTR.hide();
}
catch(e){}
break;
}
}
実装例
|
第1列
| 第2列
| 第3列
|
第1行 |
1番目 |
要素あり |
|
第2行 |
|
5番目 |
|
第3行 |
隠れていました。 |
|
|
第4行 |
|
不可視 |
ラスト |
第5行 |