参照:Useful and Handy jQuery Tips and Tricks@11
▼td要素の値が1000以上の場合にハイライト表示
1400 | 700 | 400 | 2500 | 600 | 100 |
100 | 1100 | 900 | 2600 | 1100 | 1200 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="ja" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <title>CSS:css(name, value)の使用例 | jQuery</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <!-- JS --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> //extend the jQuery functionality $.extend($.expr[':'], { //name of your special selector moreThanAThousand:function (a){ //Matching element return parseInt($(a).html()) > 1000; } }); $(function(){ $('td:moreThanAThousand').css('background-color', 'yellow'); }); </script> <!-- CSS --> <style type="text/css"> table { border:1px solid #ccc; border-spacing:0; border-collapse:collapse; } td { border:1px solid #ccc; background-color:#fff; } </style> <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head> <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1> <h3 class='h'>実行結果</h3> <div id="wrap"> <h1>CSS:css(name, value)の使用例 | jQuery</h1> <p>参照:<a href='http://www.queness.com/post/126/useful-and-handy-jquery-tips-and-tricks'>Useful and Handy jQuery Tips and Tricks@11</a></p> <p>▼td要素の値が1000以上の場合にハイライト表示</p> <!-- CODE --> <table> <tr><td>1400</td><td>700</td><td>400</td><td>2500</td><td>600</td><td>100</td></tr> <tr><td>100</td><td>1100</td><td>900</td><td>2600</td><td>1100</td><td>1200</td></tr> </table> <!-- / CODE --> </div> </body> </html>