-5

I have a table:

  <table id="fTable">
    <tbody>
        <tr id="fRow">

        </tr>
    </tbody>
  </table>

I have a Grid with 30 columns, how to do all these columns to separate <td> and want to set the <td> id, width, text or innerHtml properties.

              var row = $('#fRow');
              for(var i= 2; i < Columns.length ; i++)
               {

               }
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
GANI
  • 2,013
  • 4
  • 35
  • 69

1 Answers1

2

as i think (and the comments) ... you're new using jquery... so with jquery its very easy... append/appendTo is what you're looking for ...

if you want to add TDs more than one table it's not usefull to use ID attributes. because W3C says that IDs are unique on a page... better use the class attribute...

<table class="floatTable">
    <tbody>
        <tr class="footerRow">

        </tr>
    </tbody>
  </table>

// Select all TRs in the floatTable having the class footerRaw
$('.floatTable tr.footerRaw').each(function(key, el)) {
  // here you could define anything whatever you want
  var tdContent = 'Lorem ipsum dolor';

  // For example add five TDs to your table
  for ( var i = 0; i < 5; i++ ) {
    // if it works ;-)
    // ...it should add following:
    // <td>Lorem ipsum dolor #1</td>
    // <td>Lorem ipsum dolor #2</td>
    // ...and so on...
    $(this).append('<td>' + tdContent + ' #' + i + '</td>');
  }
});

here's an running example... http://jsfiddle.net/2am6wcm8/

HR123
  • 688
  • 1
  • 6
  • 15
  • How to add the width and Id for the td's – GANI Sep 22 '14 at 19:34
  • What width and so on you want to set? you could calculate it and so on... i prefer setting CSS... see fiddle update: http://jsfiddle.net/2am6wcm8/1/ – HR123 Sep 22 '14 at 19:40
  • PS: attributes like ID you could set with newTD.attr('id', 'yourValue'); ... see: http://jsfiddle.net/2am6wcm8/2/ ...but i think you should read the basic jQuery manual and examples for more. PS: if this answer helps you don't forget to close your question for others to find a future solution. thanks – HR123 Sep 22 '14 at 19:41