The joys of jQuery

| 0 Comments
After some experimentation today with various jQuery features, I noticed that in a "single sentence" it was possible to rapidly build up the contents of a table row. That's nothing particularly profound in its own right, but it's an example of why I like jQuery so much:

<html>
<head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        table = $("<tbody/>");
        thead = $("<thead/>");
        theadtr = $("<tr/>");              
       
        $("<th/>").text("Field 1").appendTo(theadtr)
        .clone().text("Field 2").appendTo(theadtr);
       
        theadtr.appendTo(thead);
        thead.appendTo(table);
        table.appendTo($("#container"));
    });
    </script>
</head>
<body>
    <div id="container"></div>
</body>
</html>

Leave a comment

March 2010

Sun Mon Tue Wed Thu Fri Sat
  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      

Recent Entries

Google's lossy compiler
Google's closure compiler service gets a little too frisky under ADVANCED_OPTIMIZATIONS. Original code: With advanced optimizations enabled, it was able…
The three purposes of the federal income tax law
Businesses will spend about 3.4 billion man-hours and individuals about 1.7 billion hours figuring out their taxes this year.…
Progress of a different sort
You know we have reached a level of decadence seldom seen in the history of the West when our women…

Subscribe

Advertisements

OpenID accepted here Learn more about OpenID