How can I stop jQuery functions from interfering with each other?

I have two separate (but similar) bits of jQuery code. They both work but interfere with each other. How to properly format these functions to be unique and stop them on top of each other.

Code block 1:

    $('#share-email').click(function(e) {
        e.preventDefault();
        $("#socialbox-" + $(this).attr('rel')).load('<?php echo site_url();?>club/sendtofriend/' + $(this).attr('rel'));
    return false;
    });
    $().ajaxSend(function(r,s){
        $(".social-share-container").fadeOut('fast');  
    });
    $().ajaxStop(function(r,s){
        $(".social-share-container").fadeIn('fast');
    });

      

Code 2:

    $('.djlink').click(function(e) {
        e.preventDefault();
        $("#djinfo").load($(this).attr('href'), Cufon.refresh);
    return false;
    });
    $().ajaxSend(function(r,s){
        $("#djinfo").fadeOut('fast');  
    });
    $().ajaxStop(function(r,s){
        $("#djinfo").fadeIn('fast');
    });

      

The piece of code that seems to overlap is the ajax send / stop part.

+1


a source to share


1 answer


If I am guessing correctly what you are trying to do something like this should solve:



    $('#share-email').click(function(e) {
        e.preventDefault();
        $("#socialbox-" + $(this).attr('rel')).fadeOut('fast').load('<?php echo site_url();?>club/sendtofriend/' + $(this).attr('rel'), function() {
            $(this).fadeIn('fast')
        });
        return false;
    });


    $('.djlink').click(function(e) {
        e.preventDefault();
        $("#djinfo").fadeOut('fast').load($(this).attr('href'), function() {
            Cufon.refresh();
            $(this).fadeIn('fast');
        });
        return false;
    });

      

+3


a source







All Articles