I have multiple table in which i’m showing comments. Each table have same elements.
I want to click “reply” button and select the id=”comment-id. $row[‘id’] .'” by using jquery
<tr>
<td align="right" colspan="9" id="reply-td">
<input type="button" class="reply" name="reply" value="reply" title="reply" />
</td>
</tr>
<tr>
<td align="left" colspan="9">
<input id="comment-id'. $row['id'] .'" type="hidden" value=""/>
<input id="respond'. $row['id'] .'" type="hidden" value=""/>
</td>
</tr>
Is it the only “comment-id…”-field? In that case you might do something like
Is it the only one in that table? In that case you could do
Is it neither of those? Well, then, you might do something like this:
What specific approach will work best for you can only be decided if we know exactly what assumptions you are willing to make about your DOM.
If altering the DOM isn’t out of the question, then first of all, I would add classes to the hidden fields for ease of access (
.comment-idoverinput[^="comment-id"]). You might also, if your DOM is entirely unpredictable and none of the above approaches appeal to you, addid="reply'. $row['id'] .'"to your reply button, so that you could parse the ID from there, and do this:Again, the best approach depends on what relations you know that you can rely on to always exist.