Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8683983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:10:53+00:00 2026-06-12T22:10:53+00:00

I have a dynamic table that I want to attach <col> elements with jQuery.

  • 0

I have a dynamic table that I want to attach <col> elements with jQuery.

I have this:

var tds = jQuery("tr > td").length; // count how many tds
jQuery("#colgroup-compare > col").clone() // clone
    .appendTo('#colgroup-compare'); // and append

Obviously this only appends 1 <col>, I want to append (n) numbers. How would I do this?

I have the length, I have the clone ability, now how do I combine it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:10:55+00:00Added an answer on June 12, 2026 at 10:10 pm

    With a loop :

    var $col = $("#colgroup-compare > col");
    for(var i = 0; i < n; i++){
        $col.clone().appendTo('#colgroup-compare');
    }
    

    You can’t use jQuery("#colgroup-compare > col").clone().appendTo('#colgroup-compare'); in your loop because that would append more cols at iterations > 0…

    This can be optimized :

    var $colgroup = $('#colgroup-compare'); // this saves the colgroup collection to avoid recomputing it later
    var $col = $colgroup.children("col"); // this makes the clonable col(s) from the col children of $colgroup
    for (var i=n; i-->0;){ // n times (from n-1 to 0)
        $colgroup.append($col.clone()); // append a clone of the col(s)
    }
    

    EDIT : to count the th in your first row, you may do this :

    var n=$("tr").first().children('th').length;
    

    (this avoid counting on more than one row)

    Demonstration

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a User table that I want to use with Dynamic Data. The
i have this multi dimentional array that i want to print into a table
I have a problem with jquery and a dynamic table. I want a click
I want to have a dynamic menu that feeds from a table using php
I have table that I want to remain dynamic meaning that I don't want
I have a Dynamic table that I want to give color to on alternative
I want to create a dynamic table.My problem is this that I want to
I have created a dynamic div, along with the table...I want that when i
I want to have a dynamic table, with rows added over time as a
I have a MySQL table holding lots of records that i want to give

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.