Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here's the code

JavaScript
<script>
$(document).ready(function () {
    $('a.like').click(function () {
        var next = $(this).next()
        var test = $(this).next().html();
        if ($(this).attr('class') == 'like') {
            $.post("like.cfm", {
                postid: $(this).attr("postid"),
                uid: $(this).attr("uid")
            });
 
            $(this).removeClass('like').addClass('unlike').html('Unlike');
 
            test++;
 
        } else if ($(this).attr('class') == 'unlike') {
            $.post("unlike.cfm", {
                pageID: $(this).attr("postid")
            });
 
            $(this).removeClass('unlike').addClass('like').html('Like');
 
            test--;
        }
        next.html(test);
    });
});
</script>


Here's the html

XML
<a href="##" class="unlike" postid="1234" uid="2">Unlike </a> <span class="count">100</span>
<br>
<br>
<a href="##" class="like" postid="1234" uid="2">Like</a> <span class="count">100</span>



Clicking on Like is working well but when i click on Unlike nothing happens ;->
Posted

Unlike is another link. It can't satisfy this condition, because you have attached click event only for the link having "like" class.
JavaScript
$('a.like').click(function (){
    //.....
});

If you remove the class selector, then Unlike link will also work. That is...
JavaScript
$('a').click(function (){
    //.....
});
 
Share this answer
 
Comments
liquidsmoke07 7-Jun-14 1:49am    
Hey Tadit ! Thanks.. I solved myself .. You can see :)
JavaScript
$(document).ready(function () {
    $('.la').next('a').click(function () {
        var next = $(this).next()
        var test = $(this).next().html();
        if ($(this).attr('class') == 'like') {
            $.post("lie.cfm", {
                postid: $(this).attr("postid"),
                uid: $(this).attr("uid")
            });
 
            $(this).removeClass('like').addClass('unlike').html('Unlike');
 
            test++;
 
        } else {
            $.post("ulike.cfm", {
                pageID: $(this).attr("postid")
            });
 
            $(this).removeClass('unlike').addClass('like').html('Like');
 
            test--;
        }
        next.html(test);
		return false;
    });
});


XML
<span class="la"></span><a href="##" class="unlike" postid="1234" uid="2">Unlike</a><span class="count">5</span>

<br>
<br>
<span class="la"></span><a href="##" class="like" postid="1234" uid="2">Like</a><span class="count">5</span>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900