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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:24:27+00:00 2026-06-14T18:24:27+00:00

I am putting liking and unliking link for games. Initially like is active where

  • 0

I am putting liking and unliking link for games.
Initially like is active where user click on like it will show

 unlike link 
 1 like this game

that is ok.
But when we click on unlike link it reload the page.
I dont want to reload the page

<div class="gameLikeStatus">
 <a href="likeit" id="likeitlink">Like</a>
</div>
<div class="totalLikes">
<span id="likesCount"><s:property value="likes"/></span> like this game<br>
</div>
<script>

$('a#likeitlink').bind('click',function(event){
    event.preventDefault();
    $('.gameLikeStatus').html('<a href="unlikeit" id="Unlikeitlink">Unlike</a>');
    $likesNo= $('#likesCount').html();
    $likesNo++;
    $('#likesCount').html(""+$likesNo);

}); 

$('a#Unlikeitlink').bind('click',function(event){
    event.preventDefault();
    $('.gameLikeStatus').html('<a href="likeit" id="likeitlink">Like</a>');
    $likesNo= $('#likesCount').html();
    $likesNo--;
    $('#likesCount').html(""+$likesNo);
}); 

</script>
  • 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-14T18:24:28+00:00Added an answer on June 14, 2026 at 6:24 pm

    Replace

    $('a#Unlikeitlink').bind('click',function(event){
    

    with

    $('.gameLikeStatus').on('click', '#Unlikeitlink', function(event){
    

    (and the same for the other one)

    When you’re executing $('a#Unlikeitlink').bind, the collection is empty as the link doesn’t exist yet, so this does nothing. on enables the delegation to objects not yet existing. As you didn’t bind the callback, you weren’t preventing the normal link behavior, hence your problem.

    You should also parse the html that your increment or decrement :

    $('.gameLikeStatus').on('click', '#likeitlink', function(event){
        event.preventDefault();
        $('.gameLikeStatus').html('<a href="unlikeit" id="Unlikeitlink">Unlike</a>');
        $likesNo= parseInt($('#likesCount').html(), 10) || 0;
        $likesNo++;
        $('#likesCount').html(""+$likesNo);
    }); 
    
    $('.gameLikeStatus').on('click', '#Unlikeitlink', function(event){
        event.preventDefault();
        $('.gameLikeStatus').html('<a href="likeit" id="likeitlink">Like</a>');
        $likesNo= parseInt($('#likesCount').html(), 10) || 0;
        $likesNo--;
        $('#likesCount').html(""+$likesNo);
    }); 
    

    (you could also more simply keep it in a global var instead of reading it each time)

    Demonstration

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

Sidebar

Related Questions

Putting two dashes on a page sometimes, like this -- in rare occassions messes
I am trying to link a C++ module using GCC, essentially like this: gcc
Does the FB Like button work in email newsletters? Or will this only be
Putting this at the top of your CSS file: * { margin: 0; padding:
Update Putting this at the top because it is crazy :) So some users
I putting together a page that will display a set of stored values. I
I've been putting up with this for probably too long. For some odd reason,
I'm putting the final touch on this photographer portfolio website built with Wordpress. Here's
I am putting this question again by reconstructing it....as I still not have any
Putting together a collection of Bash scripts that will be released to a wider

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.