Jquery like image changing mechanism is not working
<p>I created a like program in <code>php</code> and <code>jQuery</code>. Here is my <code>jQuery</code> code:</p>

<pre><code>$(document).ready(function(){
    $(".likethis").click(function(event){
            event.preventDefault();
            var id = $(this).attr("href");
            $.ajax({
                url: '&lt;?php echo site_url().'users/likevideo/'; ?&gt;'+id,
                success: function(data) {
                    var d =data.split('~');
                    if(d[0]==2){
                        alert('You must login to like-dislike a video!');
                    }else if(d[0]==3){
                        alert('You already liked this video');
                    }else if(d[0]==1){
                        $(".like_ico").html(d[1]);
                        $(".dilike_ico").html(d[2]);
                        $("#like_box").html('&lt;a href="#" class="likeedthis"&gt;&lt;img src="&lt;?php echo base_url(); ?&gt;images/like.jpg" /&gt;&lt;/a&gt;');                       
                        $("#dislike_box").html('&lt;a href="&lt;?php echo $vid-&gt;id; ?&gt;" class="dlikethis"&gt;&lt;img src="&lt;?php echo base_url();?&gt;images/dis_lik_over.jpg" /&gt;&lt;/a&gt;');


                    }

                }
            });


    });

    $(".dlikethis").click(function(event){
            event.preventDefault();
            var id = $(this).attr("href");
            $.ajax({
                url: '&lt;?php echo site_url().'users/dlikevideo/'; ?&gt;'+id,
                success: function(data) {
                    var d =data.split('~');
                    if(d[0]==2){
                        alert('You must login to like-dislike a video!');
                    }else if(d[0]==3){
                        alert('You already Disliked this video');
                    }else if(d[0]==1){
                        $(".dilike_ico").html(d[1]);
                        $(".like_ico").html(d[2]);                      
                        $("#dislike_box").html('&lt;a href="#" class="dlikedthis"&gt;&lt;img src="&lt;?php echo base_url(); ?&gt;images/dis_lik.jpg" /&gt;&lt;/a&gt;');
                        $("#like_box").html('&lt;a href="&lt;?php echo $vid-&gt;id; ?&gt;" class="likethis"&gt;&lt;img src="&lt;?php echo base_url();?&gt;images/like_over.jpg" /&gt;&lt;/a&gt;');
                    }
                }
            });
    });
});
</code></pre>

<p>And here is my html.</p>

<pre><code>&lt;div id="dislike_box"&gt;
                                    &lt;?php
                                        $likeimage='';
                                        $dlikeimage='';
                                        if($this-&gt;basic-&gt;get_video_liked_or_not($vid-&gt;id)==1){
                                            $likeimage ='&lt;a href="#" class="likeedthis"&gt;&lt;img src="'.base_url().'images/like.jpg" /&gt;&lt;/a&gt;';
                                        }else{
                                            $likeimage ='&lt;a href="'.$vid-&gt;id.'" class="likethis"&gt;&lt;img src="'.base_url().'images/like_over.jpg" /&gt;&lt;/a&gt;';
                                        }
                                        if($this-&gt;basic-&gt;get_video_dliked_or_not($vid-&gt;id)==1){
                                            $dlikeimage='&lt;a href="#" class="dlikedthis"&gt;&lt;img src="'.base_url().'images/dis_lik.jpg" /&gt;&lt;/a&gt;';
                                        }else{
                                            $dlikeimage='&lt;a href="'.$vid-&gt;id.'" class="dlikethis"&gt;&lt;img src="'.base_url().'images/dis_lik_over.jpg" /&gt;&lt;/a&gt;';
                                        }
                                    ?&gt;
                                    &lt;?php echo $dlikeimage; ?&gt;
                                    &lt;/div&gt;
                                    &lt;div id="like_box"&gt;
                                    &lt;?php echo $likeimage; ?&gt;
                                    &lt;/div&gt;
</code></pre>

<p>The problem is when I click the like button first time the image is changing to 'liked' image, then if I click the dislike button the page is refreshing instead of disliking the video. After refreshing I clicked the dislike again. Now it is working. But the same happens for the like button.
Can anyone  tell me why does this happen?</p>
