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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:18:27+00:00 2026-05-26T15:18:27+00:00

im creating a like system but i have ran into a problem, with when

  • 0

im creating a like system but i have ran into a problem, with when the user presses like the “like” text should change to “remove like”

the data comes from a php query so theres many items with same class

<table class="UserHistoryTable">
<td data-rowtype="stat" data-rowuser="1" data-rowid="1" class="UserHistoryTableTD">
<a href="#" class="like">Like</a></td>
</table>

data-rowuser is the id of the user pressing the like button, data-rowid is the id of the activity
what i wanna do is, when someone presses the “like” link, it should change to “Remove like”
i have tried with this code:

$('.like').click(function(){
var the_id = $(this).parent().data('rowid')
var user_id = $(this).parent().data('rowuser')
var user_id = $(this).parent().data('rowtype')
   $.ajax({
      url: "like.php",
      data: "action=likestat" + "&id=" + the_id + "&uid=" + user_id,
         success:function(response){
            var findtext = $('.UserHistoryTableTD > .like', this);
            $(findtext).replaceWith("Remove like");
       }
   });
});
  • 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-26T15:18:28+00:00Added an answer on May 26, 2026 at 3:18 pm

    You have a couple problems. this won’t still be the same value as you want in the success handler (it will have a different value related to the ajax call). And the > selector means direct child and .like is not a direct child of the parent table. If you save the value of this in a local variable, you can just use it directly in the ajax handler.

    Change the code to this:

    $('.like').click(function(){
        var the_id = $(this).parent().data('rowid')
        var user_id = $(this).parent().data('rowuser')
        var self = this;  // save for use in success handler
        $.ajax({
            url: "like.php",
            data: "action=likestat" + "&id=" + the_id + "&uid=" + user_id,
            success:function(response){
                $(self).html("Remove like");
           }
       });
    });
    

    You could also DRY it up a bit like this:

    $('.like').click(function(){
        var $self = $(this);              // save this for use later
        var $td = $self.closest("td");    // find correct parent, regardless of other markup
        $.ajax({
            url: "like.php",
            data: "action=likestat" + "&id=" + $td.data('rowid') + "&uid=" + $td.data('rowuser'),
            success:function(response){
                $self.html("Remove like");
           }
       });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting into creating some WCF services, but I have a requirement to
Creating a voting system just like stackoverflow. Questions like this have been asking several
I have something like this: private void DoSomething() { System.Console.WriteLine(Creating Foo); Foo result =
I'm creating a chat system but the user table is from a seperate database.
I have been creating Unit tests like crazy and find that I'm often having
I'm so close to getting this effect perfect, but I have run into a
All my dynamically generated action links etc. are creating links like / A ccount/
I am creating a dialog like in this page: http://jqueryui.com/demos/dialog/#modal-confirmation (click view source) on
I need to integrate the functionality of creating dynamic pages (like google sites) to
Where can I read more about creating linked slides like at the top 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.