SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery, Colorbox, and Ajax

    Hi. I have what I hope is a fairly simple problem to fix. I have a page that uses the jQuery Colorbox plugin, which I've used many times with success. In this particular case, it works fine with a simple script as follows:

    Code:
    $('a[rel=colors]').colorbox(
    {
            transition: 'fade',
            speed: 500,
            current: '{current} of {total} views'
    });
    However, because I'm using Ajax to swap the relevant content in and out from another page (on the same server), I need to use the jQuery "live" method. So now I have the following:

    Code:
    $('a[rel=colors]').live('click', function(e)
    {
            e.preventDefault();
            $.fn.colorbox(
            {
                href: $(this).attr('href'), 
                transition: 'fade',
                speed: 500,
                current: '{current} of {total} views'
            });
    });
    You can see the problem. The Colorbox works fine, except that it only includes the ONE photo that's specified in the href attribute, instead of including all photos that have the rel attribute of "colors". How can I use the "live" method while also ensuring that Colorbox grabs all of the relevant photos that have been loaded via Ajax?

    Thanks!

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Might it be necessary to remove colorBox and then to reinitialize it?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •