SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How would you avoid having multiple tables containing the same data?

    Hi.

    Say that you have a table with id Testresults.
    Now you also would like to show diffrent parts of that table inside diffrent divs that also contain a table.

    for example
    Code:
    <div id="OK testcases">
    <table id="oktestdiv">
    <tr id="row1" class="ok"><td>ok</td></tr>
    </table>
    </div>
    
    
    <div id="Failed testcases">
    <table id="failedtestdiv">
    <tr id="row2" class="failed"><td>failed</td></tr>
    </table>
    </div>
    
    
    
    <div id="all testcases">
    <table id="alltestdiv"
    <tr id="row1" class="ok"><td>ok</td></tr>
    <tr id="row2" class="failed"><td>failed</td></tr>
    </table>
    </div>
    And those rows were taken from the following table

    Code:
    <table id="testresults">
    <tr id="row1" class="ok"><td>ok</td></tr>
    <tr id="row2" class="failed"><td>failed</td></tr>
    </table>
    So how could you accomplish this?

    I naturally don't want to write the code for the table at multiple places of the page. Notice also that my site only contains of one site, containing many divs.

    Thanks

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,836
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Since a significant percentage of your visitors will not have JavaScript you'd be better to use a server side language to do it rather than have it only work for some visitors.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using jquery you could do something like:

    $("#mylink").click(function() {
    $("div#OK").append($("#testResults"));
    });

    or use could use the prepend function depending on whether you want the content to appear before or after the existing HTML.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •