Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-28-2006, 08:23 AM   PM User | #1
veejar
New to the CF scene

 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
veejar is an unknown quantity at this point
Exclamation Table column widths

Task - clone existent table without first head row.
Problem: column widths are not equal.

Code:
<html>
  <body>

  <div id='div1'>
    <table cellpadding='5' cellspacing='0' border='1' id='table1'>
      <tr>
        <td>#</td>
        <td>Cell content</td>
      </tr>
      <tr>
        <td>1</td>
        <td>text text text text text</td>
      </tr>
    </table>
  </div>

  <script type='text/javascript'><!--
    function test() {
      table1 = document.getElementById( 'table1' );
      table2 = table1.cloneNode( true );

      div = document.getElementById( 'div1' );
      div.appendChild( table2 );

      arr = [];
      row0_cells = table1.rows[0].cells;

      for ( i=0; i < row0_cells.length; i++ ) {
        arr.push( row0_cells[i].clientWidth );
      }

      table2.deleteRow( 0 );

      for ( i=0; i < arr.length; i++ ) {
        cell = table2.rows[0].cells[i];
        cell.style.width = arr[i]+'px';
      }
    }
  --></script>


  <br><br>
  <a href='#' onClick='test()'>Test</a>

  </body>
</html>
veejar is offline   Reply With Quote
Old 07-28-2006, 12:44 PM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
as long as you set a certain width for your cells:
Code:
arr.push( row0_cells[i].clientWidth );
......
cell.style.width = arr[i]+'px';
the cells will take those witdths, what else you could you expect? What's the use of seting them those width?

Why not simply clone the second row and append it to the table? What is the use to append the whole table?
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:50 PM.


Advertisement
Log in to turn off these ads.