Search code examples
javascriptprototypejs

js prototype table creation


I am using prototype in my application for making javascript calls and updating data on the screen. My question is, when I'm trying to create a table, I saw an example:

    var tableProto = new Element('table').update('<thead><tr><th>Situation Task</th><th>Action</th><th>Result</th></tr></thead><tbody><tr><td>a</td><td>b</td><td>c</td></tr></tbody>');

With this tableProto element, how do I put it inside of a div on the page?

    var tableProto = new Element('table').update('<thead><tr><th>Situation Task</th><th>Action</th><th>Result</th></tr></thead><tbody><tr><td>a</td><td>b</td><td>c</td></tr></tbody>');
$('tableDiv').update(tableProto);

Solution

  • Lets say you have a <div id="mydiv"></div> with your table element in the tableProto variable.

    $('mydiv').update(tableProto);
    

    Will replace the contents of the div with the table.

    $('mydiv').insert(tableProto);
    

    will insert the table after all the content in the div.