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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:03:18+00:00 2026-05-29T11:03:18+00:00

i have this bit of html. (Link at bottom) Its output of php code

  • 0

i have this bit of html.
(Link at bottom)

Its output of php code for status updates, it has view comments and post comment link, the post comment link uses jquery to add a textarea and submit button below that status update. and the view comments shows the comments to that status update below that status update.

So i use php looping so there will be obviously more than 1 status updates at most times(depends on how much friends users have) so i cant have an element like ‘textelement’, i will need to have elements like ‘textelement1’ and ‘textelement2’
So i used php to add the id of the status update in the end of the links like _id so the element id becomes view_comments_1.

So i want to use jquery to find out which element has been clicked so that i can add a text box and show comments below the right status update instead of showing it below all status updates.

HTML

<div class="wrapbg">

    <span class="corners-top"><span></span></span>
    <div id="content"><br/>
        Whats new?
        <hr class='hr1'>

        <div class='stbody' id='stbody'>

            <div class='stimg'>
                <img src='uploads/profile_pics_small/Anonymous_Blueprint_Wallpaper_by_co.jpg' /></img>
            </div>
            <div class='sttext'>
                Welcome yoall!!
                <div class='sttime'>By LUcase</div>
                <br><br>

                <a href=''>0 Likes</a> <a href=''>1 Dislikes</a>
            </div>
            <a href=''>unDislike</a> <a id='comment_now_1' href=''>Comment</a> <a id='view_comments1' data-id-1 = '1' href=''>View comments</a> <div id='emptydiv1'> </div></div>
        <div class='stbody' id='stbody'>

            <div class='stimg'>

                <img src='uploads/profile_pics_small/wood_texture_by_pabloalvin-d1igijr.jpg' /></img>
            </div>
            <div class='sttext'>
                hi
                <div class='sttime'>By nicknick</div>
                <br><br>
                <a href=''>0 Likes</a> <a href=''>0 Dislikes</a>
            </div>
            <a href=''>Like</a> <a href=''>DisLike</a> <a id='comment_now_4' href=''>Comment</a> <a id='view_comments4' data-id-4 = '4' href=''>View comments</a> <div id='emptydiv4'> </div></div></div>

    <span class="corners-bottom"><span></span></span>
</div>

JavaScript

    //Gotta find out which status update we are dealing with!
    jQuery("document").ready(function(){
        jQuery(".likebtn").click(function(e) {
            var id=jQuery(this).attr("data-id");
            jQuery.post('like.php', {'id': id}, function(data) {
                alert("Your like.php has been called");
            }, "json");
            e.preventDefault();
        });
        jQuery(".dislikebtn").click(function(e) {
        });

//gotta figure out which status update we are dealing with!
//attache the click event to the anchor tag
        $("#comment_now").live("click",function(e){
            //prevent the default behaviour of following the link
            e.preventDefault();
            $("#comment_now").remove();
            //find the textarea element, and after it, put an input tag
            $(".sttext").after('<textarea id="comment_text" name="comment"></textarea> <br> <button id = "post_button" class="action greenbtn"><span class="label">Comment</span></button> <a id="cancel_comment" href="">Cancel</a> <br id="com_spacing">');
        });



//gotta figure out which status update we are dealing with!
        $("#cancel_comment").live("click",function(event){
            event.preventDefault();
            $("#comment_text").remove();
            $("#cancel_comment").remove();
            $("#post_button").remove();
            $("#com_spacing").remove();
            $("#view_comments").before('<a href="" id="comment_now">Comment</a> ');
        });

        $("#view_comments").live("click", function(e){
            e.preventDefault();
            var id=jQuery(this).attr("data-id");
            $.ajax({

                url: 'query_comments.php?status_id='+id,
                beforeSend: function( xhr ) {
                    xhr.overrideMimeType( 'text/plain; charset=UTF-8' );
                },
                success: function( data ) {
                    $('#emptydiv').html(data);
                }
            });
        });
    });

Please help me out 🙂

  • 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-29T11:03:19+00:00Added an answer on May 29, 2026 at 11:03 am

    add a class to to action buttons and pass the comment id as data attribute like so:

    <a class="commentBtn" href='' data-commentid="1">Comment</a>

    and than you can read out the id easily with jquery:

    $(".commentBtn").live("click",function(e){
    var id = $(this).data('commentid');
    e.preventDefault();
    // do something with id…
    });

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

Sidebar

Related Questions

its a little bit hard to understand. in the header.php i have this code:
I have this bit of html code, but when I click the link, it
I have this bit of code I found on the web at the end
Well, I have this bit of code that is slowing down the program hugely
I use this bit of code to feed some data i have parsed from
I have this problem with a link in an HTML page where the first
I am using this bit of jQuery code to get href of the link:
index.php has this jquery code which loads notifications.inc.php into a div on the page
So I have this bit of python code that runs through a delicious page
I have a bit of code in this in-development page . It is the

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.