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

  • SEARCH
  • Home
  • 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 6926377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:54:39+00:00 2026-05-27T10:54:39+00:00

I am using jQuery to inject values from an JSON object into an existing,

  • 0

I am using jQuery to inject values from an JSON object into an existing, empty table.

What I want to do is fill up my table top-to-bottom, instead of what it does now – left to right. So how would I modify this snippet to accomplish what I want?

_.each(dataset, function(v, k){
    $("tr td:empty:first", "#myTable tbody").html("<strong>"+v+"</strong>");
});

I guess that It would be possible to target the td in the column which has the fewest filled rows, but how?

  • 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-05-27T10:54:40+00:00Added an answer on May 27, 2026 at 10:54 am

    Change your selector to:

    $("tr td:empty:first:first-child", "#myTable tbody")
    

    So that it matches only when the table cell is the first-child of it’s parent, the row, so will only insert in the first column.


    Edit: A method to populate the table based on a known and limited number of columns

    It works by selecting each table column using the nth-child of each row, then concatenating the columns together, and filtering for the first empty one.

    var cells = [].concat(
        $('tr td:nth-child(1)').get(),
        $('tr td:nth-child(2)').get(),
        $('tr td:nth-child(3)').get(),
        $('tr td:nth-child(4)').get()
    )
    _.each(dataset, function(v, k){
      $(cells).filter(':empty:first').html("<strong>"+v+"</strong>");
    });
    

    Edit: Generic version

    // create array to hold cells ordered by column
    var cells = [];
    // loop through desired columns adding to cells array
    // hint: you can specify column `from` and `to` in the for loop definition
    for(i=1;i<=4;i++)
      cells = cells.concat($('tr td:nth-child('+i+')').get());
    
    // loop through the data, populating each column in order
    _.each(dataset, function(v, k){
      $(cells).filter(':empty:first').html("<strong>"+v+"</strong>");
    });    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to inject jQuery into a page using the Google AJAX Libraries API,
I am trying to load some JSON data into to a table using the
Using jQuery, how do you bind a click event to a table cell (below,
Using jQuery, how do I delete all rows in a table except the first?
I am looking for a way to inject values from the fragment (#) of
Is it safe to inject JQuery's script using JsonP? The installation of my web
I am using jQuery.ajax ( http://docs.jquery.com/Ajax/jQuery.ajax ) to inject the contents of a different
I am using a jquery dialog and want to set the .html value with
I was using jQuery.load() to load a html page's content into a lightbox. The
I am using JQuery to inject dynamically script tags in the body tab of

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.