The joys of jQuery

| 0 Comments | 0 TrackBacks
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>

No TrackBacks

TrackBack URL: http://www.codemonkeyramblings.com/mt/mt-tb.cgi/1634

Leave a comment

Recent Entries

Engineers and terrorism
So what makes engineers more likely to become terrorists? The most obvious theory is their technical expertise; al-Qaida and other…
Next project
WPtouch is a great plugin for WordPress and Melody/Movable Type need something like it. The way that I chose to…
A lesson in why "cheaper != better" for businessmen
I have no Internet access at my house because the subcontractors that Verizon is using to replace union labor (note:…

Subscribe

Advertisements

OpenID accepted here Learn more about OpenID