summaryrefslogtreecommitdiffstats
path: root/jquery-striped-table.xhtml
blob: 7d726505daaaa65ec93a337a8ae8a97c78f6f2a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!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">
<head>
<title>hello, world!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
    table { border: 1px solid gray; font-size: 0.8em }
    thead { font-weight: bold }
    td { max-width: 400px }
    tr, td { border: 1px solid black }
    .stripe1 { background-color: #0f0 }
    .stripe2 { background-color: #afa }
    .highlight { background-color: #ffcc00 }
</style>
<script type="text/javascript" src="jquery-2.0.2.js"></script>
<script type="text/javascript">
<![CDATA[
    $(function() {
        $("p:last").css("border", "2px solid green");

        $("table tr:even").addClass("stripe1");
        $("table tr:odd").addClass("stripe2");

        $("#list1 tr").hover(function() {
            $(this).toggleClass("highlight");
        }, function() {
            $(this).toggleClass("highlight");
        });

        <!-- this is a jquery wrapped variable? -->
        <!-- attach an event to a table instead of to each tr -->
        $("#list1").on("click", "tr", function() {
            alert($(this).text());
        });
    });
]]>
</script>
</head>
<body>
<h1>hello, world!</h1>
<table id="list1">
  <thead>
  <tr>
    <td>OPAMP</td>
    <td>Description</td>
    <td>Do I own one?</td>
  </tr>
  </thead>
  <tr>
    <td>OPA2227</td>
    <td>Laid back BB sound, great 80Hz bass, but muddy mids and highs</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>OPA637</td>
    <td>Exceptional performance all around. Almost too detailed for music</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>LM4562</td>
    <td>I guess it was great? It burned down</td>
    <td>No</td>
  </tr>
  <tr>
    <td>NE5532</td>
    <td>Sounded alright, but high DC offset!</td>
    <td>Yes, 100x</td>
  </tr>
  <tr>
    <td>741</td>
    <td>Not for music amplification</td>
    <td>Yes</td>
  </tr>
</table>
<p>goodbye, world!</p>
</body>
</html>