1

I have two functions:

$(function() {
    $(".deactivated").click(function() {           
          var Container = $(this).parent();             
       var id = $(this).attr("id");             
        var string = 'id='+ id ;    
        $.ajax({   
            url: "<?php echo site_url('social/activate') ?>",
            type: "POST",
            data: string,
            cache: false,
                 success: function(){
                     Container.fadeOut(1000, function(){
                     $(this).load("<?php echo site_url('social/social_icon') ?>", {id: id}, function(){
                         $(this).hide().fadeIn(700);
                         $(this).click();
                     })
                 });
            }   
        });
        return false;
    });
});

 $(function() {
    $(".activated").click(function() {           
          var Container = $(this).parent();             
       var id = $(this).attr("id");             
        var string = 'id='+ id ;    
        $.ajax({   
            url: "<?php echo site_url('social/deactivate') ?>",
            type: "POST",
            data: string,
            cache: false,
                 success: function(){
                     Container.fadeOut(1000, function(){
                     $(this).load("<?php echo site_url('social/social_icon') ?>", {id: id}, function(){
                         $(this).hide().fadeIn(700);
                     })
                 });
            }   
        });
        return false;
    });
});

One is to activate link and other is to deactivate it. Functions are working fine, but when link is activated or deactivated, it can't be clicked again to change it (page needs to be refreshed in order for functions to work again). What I need to do to make it work?

1
  • Are you changing the class of the links?! deactivated=> activated and activated => deactivated Commented Sep 28, 2011 at 8:47

3 Answers 3

3

Change:

$(".activated").click(function() {
$(".deactivated").click(function() { 

To:

$(".activated").live('click',function() {  
$(".deactivated").live('click',function() { 
Sign up to request clarification or add additional context in comments.

Comments

1

You seem to be replacing the container and the elements inside it, so the elements that had the click events bound to them will have been removed.

You can fix this by changing your event handlers to use live:

$(".deactivated").live('click', function() { 

and

$(".activated").live('click', function() {

Comments

0

Looks like you're replacing the links that you click which loses the event bindings.

Change the .click() to use .live('click'..

$(".deactivated").live('click', function() {           

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.