jquery addresses and live method

Posted by Jay on Stack Overflow See other posts from Stack Overflow or by Jay
Published on 2010-04-03T10:42:07Z Indexed on 2010/04/03 10:53 UTC
Read the original article Hit count: 436

Filed under:
|
|
|
//deep linking 
$.fn.ajaxAnim = function() {
    $(this).animW();
    $(this).html('<div class="load-prog">loading...</div>');
}

$("document").ready(function(){
    contM = $('#main-content');
    contS = $('#second-content');
    $(contM).hide();
    $(contM).addClass('hidden');
    $(contS).hide();
    $(contS).addClass('hidden');
    function loadURL(URL) {
        //console.log("loadURL: " + URL);
        $.ajax({ url: URL, 
                beforeSend: function(){$(contM).ajaxAnim();},
                type: "POST",
                dataType: 'html',
                data: {post_loader: 1},
                success: function(data){
                    $(contM).html(data);
                    $('.post-content').initializeScroll();
                    }
        });
    }

    // Event handlers
    $.address.init(function(event) {
        //console.log("init: " + $('[rel=address:' + event.value + ']').attr('href'));
    }).change(function(event) {
        evVal = event.value;
        if(evVal == '/'){return false;}
        else{
            $.ajax({ url: $('[rel=address:' + evVal + ']').attr('href'), 
                    beforeSend: function(){$(contM).ajaxAnim();},
                    type: "POST",
                    dataType: 'html',
                    data: {post_loader: 1},
                    success: function(data){
                        $(contM).html(data);
                        $('.post-content').initializeScroll();
            }});
        }
        //console.log("change");
    })

    $('.update-main a, a.update-main').live('click', function(){
        loadURL($(this).attr('href'));
        return false;
    });

  $(".update-second a, a.update-second").live('click', function() {
    var link = $(this);
        $.ajax({ url: link.attr("href"),
                beforeSend: function(){$(contS).ajaxAnim();},
                type: "POST",
                dataType: 'html',
                data: {post_loader: 1},
                success: function(data){
                    $(contS).html(data);
                    $('.post-content').initializeScroll();
        }});
        return false;
  });

});

I'm using jquery addresses to update content while maintaining a useful url. When clicking on links in a main nav, the url is updated properly, but when links are loaded dynamically with ajax, the url address function breaks.

I have made 'click' events live, allowing for content to be loaded via dynamically loaded links, but I can't seem to make the address event listener live, but this seems to be the only way to make this work. Is my syntax wrong if I change this :

$.address.change(function(event) {

to this:

$.address.live('change', function(event) {

or does the live method not work with this plugin?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about addresses