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 1086985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:52:54+00:00 2026-05-16T22:52:54+00:00

First of all let me know if my question is completely vague or doesnt

  • 0

First of all let me know if my question is completely vague or doesnt make any sense.

What I am trying to do is:

I Have a page which displays some blocks of data (Block can be considered as a row of data). Each block will be seperate <DIV> and inside this <DIV> I have Nested two tables.

My question, How do I populate or generate a different “id” for every html tag thats responsible for display. I need to do this because I am using Jquery to process user click events and to generate json data which will be sent back to the server.

Also the data for the screen will come as a json data type. Sample mock of one <DIV> is attached

<div id="1" class="RedColor" >
<table id="tab1" class="recordTable">
<tr>
<td id="studentName1" class="studentName">
<table id="innertab1" border="0" width="100%" cellpadding="3">
 <tr>
  <td id="" class="error1" width="172">&nbsp;</td>
  <td id="rollNumber1" class="rollNumber" width="50">12</td>
  <td id="" class="studentName" colspan="2">ABC XYZ</td>
 </tr>

</table>
</td>
<td width="64" valign="top">

</td>
</tr>
</table>
</div>
  • 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-16T22:52:54+00:00Added an answer on May 16, 2026 at 10:52 pm

    I would handle this problem differently.

    I would assign a unique ID only to each “block” of data. Within that block I would only use classes to identify each element of the data.

    Each class within one block would be unique.

    So this is what my HTML would look like (note the class rename to make them unique within each data block)

    <div id="data1" class="RedColor" >
        <table class="recordTable">
            <tr>
                <td class="studentNameData">
                    <table class="innerTab" border="0" width="100%" cellpadding="3">
                        <tr>
                            <td class="studentName"> ... </td>
                            ...
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <div id="data2" class="RedColor" >
        <table class="recordTable">
            ...
    

    You could even get rid of the div wrapper and put the unique ID on each outer table.

    Now each piece of data can be uniquely identified using the form: [ Data Block ID ] [ Class Name ].

    In jQuery that can be done using the .find() method.

    For example to retrieve the studentName from data block 3 I would use

     $("#data3").find(".studentName").text();
    

    I would iterate over the data you get from the server to populate the tables. Here is an extremely simplified version just to illustrate what I described. I removed the outer DIV wrapper and added the unique ID to the table, just so you can see what that would look like:

    Simplified example:

    // Function to add an empty table with class names
    var $addTable = function() {
        // The table could be built with multiple methods too.
        return $('<table><tr><td class ="name"></td></tr></table>');
    }   
    
    $(function() {
    
        // The attribute = selector
        $("input[value='Get data']").click(function() {
    
            // Loading notice
            $("#showData").html("Loading...");
    
            // The AJAX call to get the data using POST
            $.post('/ajax_json_echo/', function(data) {
    
                // Clear loading notice
                $("#showData").html("");
    
                // Iterate through data
                //   and create a table for each item.            
                $.each(data, function(index, value) {
    
                    // This is the div's unique ID
                    var $id = "data" + index;
    
                    $addTable().attr("id", $id).appendTo("#showData");
                    $("#" + $id).find(".name").html(value);
                });
            });
        });
    });​
    

    jsFiddle example

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

Sidebar

Related Questions

The Disclaimer First of all, I know this question (or close variations) have been
First of all let me tell you that i have read the following questions
First question. If I screwed up somehow let me know. Ok, what I need
First of all, sorry for the vague title. Let me explain. At work we're
Hopefully this will make sense. I have a page where an user can create
First time posting, please let me know if this question has already been answered!
First off, let me begin by saying I KNOW that this question has been
First of all, I would like to let you know that I am new
First of all let me just say, I know, there is such thing as
First of all, let me please clarify that I know absolutely nothing about regular

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.