简体   繁体   中英

Add col to the colgroup of html table in run time

I have define the table with the following code snippet.

<div class="gridheadercontainer">
        <table class="table" cellspacing="0">
            <colgroup>
                <col style="width: 150px;">
                <col style="width: 150px;">
                <col style="width: 150px;">
                <col style="width: 150px;">
                <col style="width: 150px;">
            </colgroup>
           <thead>
           <tr class="columnheader" style="cursor: pointer;">
               <th class="headercell"><div class="headercelldiv">Task name</div></th>
               <th class="headercell"><div class="headercelldiv">Start time</div></th>
               <th class="headercell"><div class="headercelldiv">End time</div></th>
               <th class="headercell"><div class="headercelldiv">Duration</div></th>
               <th class="headercell"><div class="headercelldiv">Status</div></th>
               <th class="headercell"><div class="headercelldiv"></div></th>
           </tr>
          </thead>
            <tbody class="hide"><tr><td></td><td></td><td></td><td></td><td></td></tr></tbody>
        </table>
    </div>

In this case I have use the following code snippet to append the col to the colgroup of table.

$('.gridheadercontainer table colgroup').prepend(doc.createElement('col'));

But it will add the column in the 0th index. How to the col to the last of the colgroup table

你的意思是append()

$('.gridheadercontainer table colgroup').append(doc.createElement('col'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM