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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:22:11+00:00 2026-05-24T21:22:11+00:00

I have a Ajax ‘like’ button that uses jQuery, this button will be used

  • 0

I have a Ajax ‘like’ button that uses jQuery, this button will be used multiple times on a page. I don’t really want to include the jQuery script multiple times, so is there a way to get the jQuery to work for all like buttons on the page, but uses the unique ID from each post. This may be a noob question, but thats what I am. Any sulutions you can offer will be great. Thanks!

Code:

jQuery:

<script type="text/javascript">
$(function() {
$(".like").click(function(){
$("#loading").html('<img src="loader.gif" align="absmiddle">&nbsp;loading...');

 $.ajax({
   type: "POST",
   url: "like.php?id=<?php $row['uid']; ?>", // UNIQUE ID, EVERY POST WILL HAVE ONE
   success: function(){
$("#loading").ajaxComplete(function(){}).slideUp();
$('#like'+I).fadeOut(200).hide();
$('#remove'+I).fadeIn(200).show();
}
});
return false;

});

});
</script>

<script type="text/javascript">
$(function() {
$(".remove").click(function(){
$("#loading").html('<img src="loader.gif" align="absmiddle">&nbsp;loading...');

 $.ajax({
   type: "POST",
   url: "remove.php?id=<?php $row['uid']; ?>", /// UNIQUE ID, EVERY POST WILL HAVE ONE
   success: function(){
$("#loading").ajaxComplete(function(){}).slideUp();
$('#remove'+I).fadeOut(200).hide();
$('#like'+I).fadeIn(200).show();
}
});
return false;

});

});
</script>

HTML:

<div id="follow1"><a href="#" class="follow" id="1">

<span style="font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; font-weight: bold; color:#7391AC; text-align:left; font-size:20px; text-align:left;">&nbsp;<strong>like</strong>
</span></a>
</div>

<div id="remove1" style="display:none"><a href="#" class="remove" id="1">

<span class="remove_b" style="font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; font-weight: bold; color:#7391AC; text-align:left; font-size:20px; text-align:left;">unlike
</span></a>
</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-24T21:22:12+00:00Added an answer on May 24, 2026 at 9:22 pm

    you could store the id on a containing element, and get that with each click, like so;

    html

    <div class="box" data-id="1">
        <a href="#" class="like">like</a>
        <a href="#" class="remove">remove</a>
        <!--etc-->
    </div>
    

    javascript

    $(function() {
        $(".like, .remove").click(function(e) {
    
            var id = $(this).closest('.box').data('id');
            var url = $(this).attr('class') + ".php?id=" + id;
            // a click on like will generate a url: like.php?id=1
    
        });
    });
    

    demo at http://jsfiddle.net/6Vrvv/

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

Sidebar

Related Questions

I have jQuery ajax requesting a page that returns html with <script> tags inside
I am using asp.net MVC to develop an application that will have ajax interactions.
This should be simple. I have ajax returning string, with multiple divs. I need
I have a ajax method that renderes a @collection of users. This code is
I have an AJAX Application that I have been working on. At this point
I have a page ' foo.html ' that populates a table via AJAX 'ajax.html?options=option1'
I would like to have Ajax form in Rails so i'm using form_remote_tag. The
I have a series of dynamically generated inputs that I need to have ajax
With ASP.NET MVC, it is common to have AJAX code(e.g. jQuery) to invoke web
I have some AJAX work that brings across an additional form element that I

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.