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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:31:25+00:00 2026-06-01T09:31:25+00:00

How do I differentiate between elements inside a table that is populated using a

  • 0

How do I differentiate between elements inside a table that is populated using a loop? So that when I use Javascript to show an element on click, it will show the correct element?

Currently, when I click comment, it just shows the first item, and then the rest of the rows don’t work.

When the user clicks the comment button, I want a textarea to appear. The problem is that since it is a table, how do i make it so each comment button in the table shows the box within its table. do i need to add an incrementing id to each row in the table?

Here is the Javascript:

$('#postcomment').click(function(){
$('#comment_text').css('display','inline');
})

Here is the PHP:

<table>
<?php
foreach ($posts as $key => $list){
echo "<tr>";
echo "<td>
<a id='postcomment'>Comment</a>
<textarea  id='comment_text' style='display:none;placeholder='Type your comment.'></textarea>
      </td>";
echo "</tr>";               
}
?>
</table>

Is the best solution for this, to give each row a unique id, and how would I do this? Also, how would I then call the Javascript to work for each unique id?

  • 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-01T09:31:26+00:00Added an answer on June 1, 2026 at 9:31 am

    ids must be unique within a document. Instead use a class. Once you do that, you can use things such as parent, siblings, find, etc. to find the appropriate element based on the location of the one you clicked.

    Something like this:

    $('.postcomment').click(function(){
        $(this).next('.comment_text').css('display','inline');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using a jquery accordian that uses hash marks to differentiate between open accordion
I am using Backbone and decided that I wanted a way to differentiate between
I want to be able to differentiate between a string that is alphnumeric and
I have to differentiate between the real addresses and the VM addresses using any
I am using Google analytics and wish to differentiate between two different cases on
Why do some languages differentiate between methods that return a value and methods that
How do you differentiate between a one space tab and one that takes up
Using C#, is there are way to differentiate between ConnectionStrings in the machine.config and
How to differentiate between different items in list view, using ListActivity(Android) . For example
Is there something in jquery that would allow me to differentiate between behavior on

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.