Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9001053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:23:10+00:00 2026-06-16T00:23:10+00:00

I have multiple colorbox in one page. those colorbox’s links are generated with javascript.

  • 0

I have multiple colorbox in one page.

those colorbox’s links are generated with javascript.

Now every time a new link that opens a colorbox get generated any clicked link associated with colorbox will go to that new link’s url.

this is how i declared the colorbox:

$('.ajax').colorbox();

the href in the link are correct but still send to the last generated link’s href.

Thanks in advance.

Edit :
this is the code how i add some links:

$('.albums').live('click', function(e){
    e.preventDefault();
    e.stopPropagation();
    parent_id           = $(this).parents().eq(2)[0].id;
    parent_header       = $('#' + parent_id + ' header')[0].innerHTML;
    parent_section      = $('#' + parent_id + ' section')[0].innerHTML;
    parent_footer       = $('#' + parent_id + ' footer')[0].innerHTML;
    fragment            = $(this).attr('href').split('/')[$(this).attr('href').split('/').length - 1];
    parent              = $(this).parents().eq(2)[0].id;
    if(fragment.indexOf('_-_') !== -1)
        page = fragment.replace('_-_', '/');
    else
        page = fragment;
    old_data[parent_id] = {'header': parent_header, 'footer': parent_footer, 'section': parent_section, 'link': parent + '/' + page};
    $.post('files/get_page', { page: old_data[parent_id]['link'] }, function(data){
        ret     = JSON.parse(data);
        a       = $('<a>').addClass('reset_link').attr('href', '#').append('Back To Albums');
        a.click(function(e){
            e.preventDefault();
            e.stopPropagation();
            this_parent_id      = $(this).parents().eq(1)[0].id;
            $('#' + this_parent_id + ' header').html(old_data[this_parent_id]['header']);
            $('#' + this_parent_id + ' section').html(old_data[this_parent_id]['section']);
            $('#' + this_parent_id + ' footer').html(old_data[this_parent_id]['footer']);
        })
        $('#' + parent).children().eq(0).html(a);
        $('#' + parent).children().eq(0).append(ret.header);
        $('#' + parent).children().eq(1).html('');
        for(i in ret.body.images){
            href            = ret.body.href + ret.body.images[i].image_name;
            image_id        = ret.body.images[i].image_id;
            delete_div_id   = 'delete_image_' + image_id;
            body            = $('<div>').addClass('albums_div');
            delete_div      = $('<div>').addClass('delete').append('&#10006; Supprimer').attr('id', image_id);
            a               = $('<a>').addClass('lightbox').attr('href', href);
            a.attr('onclick', 'return false;');
            a.append('&#9673; ' + ret.body.images[i].image_name);
            delete_div.click(function(){
                id          = delete_div_id;
                id_array    = id.split('_');
                $.post('files/delete', { id: image_id, del: id_array[1] }, function(data){
                    $(body).remove();
                });
            });
            body.append(a);
            body.append(delete_div);
            $('#' + parent).children().eq(1).append(body);
            $('.lightbox').colorbox({rel: 'group1'});
        }

        footer  = $('<a>').addClass(ret.footer['attr'].class).attr('id', ret.footer['attr'].id).attr('href', ret.footer['href']);
        footer.append(ret.footer['text']);
        footer.click(function(e){
            e.preventDefault();
            $.colorbox({href: ret.footer['href']});
        });
        $('#' + parent).children().eq(2).html(footer);
    });
});

NOTE: the code generates the right links with the correct href but the problem in the colorbox it self. and I knew this because i did this:

i assigned a live click event to the links with the colorbox like this:

$(".upload_file").live('click', function(){
    console.log($(this)[0].href);
});

and the href printed to the console’s the right one but the page that was displayed in the colorbox is wrong.

Edit 2 adding the HTML:

the page before the javascript changing the code:

<section id="reference">
    <header class="inner_header"><h3>R&#201;F&#201;RENCE PAGE SECTION</h3></header>
    <section>
        <h4>Choose an album :</h4>
        <div class="albums_div">
            <a href="res_yass" onClick="return false;" class="albums">&#9733; R&#233;sidence YASSINE</a>
            <div class="delete" id="delete_album_1">&#10006; Supprimer</div>
        </div>
        <div class="albums_div">
            <a href="res_nesr" onClick="return false;" class="albums">&#9733; R&#233;sidence NESRINE</a>
            <div class="delete" id="delete_album_2">&#10006; Supprimer</div>
        </div>
        <div class="albums_div">
            <a href="azerty" onClick="return false;" class="albums">&#9733; Azerty</a>
            <div class="delete" id="delete_album_8">&#10006; Supprimer</div>
        </div>
    </section>
    <footer class="inner_footer"><a href="files/add/reference" class="add_album ajax" id="reference">Add an album</a></footer>
</section>

the page after javascript change the code:

<section id="reference">
    <header class="inner_header"><a class="reset_link" href="#">Back To Albums</a><h4>Azerty</h4></header>
    <section>
        <div class="albums_div">
            <a class="lightbox cboxElement" href="f352702127.jpg" onclick="return false;">◉ f352702127.jpg</a>
            <div class="delete" id="128">✖ Supprimer</div>
        </div>
        <div class="albums_div">
            <a class="lightbox cboxElement" href="f65564287.jpg" onclick="return false;">◉ f65564287.jpg</a>
            <div class="delete" id="129">✖ Supprimer</div>
        </div>
        <div class="albums_div">
            <a class="lightbox cboxElement" href="f184021055.jpg" onclick="return false;">◉ f184021055.jpg</a>
            <div class="delete" id="130">✖ Supprimer</div>
        </div>
    </section>
    <footer class="inner_footer"><a class="upload_file ajax" id="azerty" href="uploader/get_form/reference/azerty">Upload une image</a></footer>
</section>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:23:11+00:00Added an answer on June 16, 2026 at 12:23 am

    solved, the problem wasn’t with the colorbox i just chenge the code from this:

    $('.albums').live('click', function(e){
        e.preventDefault();
        e.stopPropagation();
        parent_id           = $(this).parents().eq(2)[0].id;
        parent_header       = $('#' + parent_id + ' header')[0].innerHTML;
        parent_section      = $('#' + parent_id + ' section')[0].innerHTML;
        parent_footer       = $('#' + parent_id + ' footer')[0].innerHTML;
        fragment            = $(this).attr('href').split('/')[$(this).attr('href').split('/').length - 1];
        parent              = $(this).parents().eq(2)[0].id;
        if(fragment.indexOf('_-_') !== -1)
            page = fragment.replace('_-_', '/');
        else
            page = fragment;
        old_data[parent_id] = {'header': parent_header, 'footer': parent_footer, 'section': parent_section, 'link': parent + '/' + page};
        $.post('files/get_page', { page: old_data[parent_id]['link'] }, function(data){
            ret     = JSON.parse(data);
            a       = $('<a>').addClass('reset_link').attr('href', '#').append('Back To Albums');
            a.click(function(e){
                e.preventDefault();
                e.stopPropagation();
                this_parent_id      = $(this).parents().eq(1)[0].id;
                $('#' + this_parent_id + ' header').html(old_data[this_parent_id]['header']);
                $('#' + this_parent_id + ' section').html(old_data[this_parent_id]['section']);
                $('#' + this_parent_id + ' footer').html(old_data[this_parent_id]['footer']);
            })
            $('#' + parent).children().eq(0).html(a);
            $('#' + parent).children().eq(0).append(ret.header);
            $('#' + parent).children().eq(1).html('');
            for(i in ret.body.images){
                href            = ret.body.href + ret.body.images[i].image_name;
                image_id        = ret.body.images[i].image_id;
                delete_div_id   = 'delete_image_' + image_id;
                body            = $('<div>').addClass('albums_div');
                delete_div      = $('<div>').addClass('delete').append('&#10006; Supprimer').attr('id', image_id);
                a               = $('<a>').addClass('lightbox').attr('href', href);
                a.attr('onclick', 'return false;');
                a.append('&#9673; ' + ret.body.images[i].image_name);
                delete_div.click(function(){
                    id          = delete_div_id;
                    id_array    = id.split('_');
                    $.post('files/delete', { id: image_id, del: id_array[1] }, function(data){
                        $(body).remove();
                    });
                });
                body.append(a);
                body.append(delete_div);
                $('#' + parent).children().eq(1).append(body);
                $('.lightbox').colorbox({rel: 'group1'});
            }
    
            footer  = $('<a>').addClass(ret.footer['attr'].class).attr('id', ret.footer['attr'].id).attr('href', ret.footer['href']);
            footer.append(ret.footer['text']);
            footer.click(function(e){
                e.preventDefault();
                e.stopPropagation();
                $.colorbox({href: ret.footer['href']});
            });
            $('#' + parent).children().eq(2).html(footer);
        });
    });
    

    to this:

    $('.albums').live('click', function(e){
        e.preventDefault();
        e.stopPropagation();
        parent_id            = $(this).parents().eq(2)[0].id;
        parent_header        = $('#' + parent_id + ' header')[0].innerHTML;
        parent_section       = $('#' + parent_id + ' section')[0].innerHTML;
        parent_footer        = $('#' + parent_id + ' footer')[0].innerHTML;
        fragment             = $(this).attr('href').split('/')[$(this).attr('href').split('/').length - 1];
        parent               = $(this).parents().eq(2)[0].id;
        if(fragment.indexOf('_-_') !== -1)
            page = fragment.replace('_-_', '/');
        else
            page = fragment;
        old_data[parent_id]   = {'header': parent_header, 'footer': parent_footer, 'section': parent_section, 'link': parent + '/' + page};
        $.post('files/get_page', { page: old_data[parent_id]['link'] }, function(data){
            ret = JSON.parse(data);
            swap_content(ret);
        });
    });
    function swap_content(ret){
        a      = $('<a>').addClass('reset_link').attr('href', '#').append('Back To Albums');
        a.click(function(e){
            e.preventDefault();
            e.stopPropagation();
            this_parent_id = $(this).parents().eq(1)[0].id;
            $('#' + this_parent_id + ' header').html(old_data[this_parent_id]['header']);
            $('#' + this_parent_id + ' section').html(old_data[this_parent_id]['section']);
            $('#' + this_parent_id + ' footer').html(old_data[this_parent_id]['footer']);
        })
        $('#' + parent).children().eq(0).html(a);
        $('#' + parent).children().eq(0).append(ret.header);
        $('#' + parent).children().eq(1).html('');
        for(i in ret.body.images){
            href            = ret.body.href + ret.body.images[i].image_name;
            image_id        = ret.body.images[i].image_id;
            delete_div_id   = 'delete_image_' + image_id;
            body            = $('<div>').addClass('albums_div');
            delete_div      = $('<div>').addClass('delete').append('&#10006; Supprimer').attr('id', image_id);
            a               = $('<a>').addClass('lightbox').attr('href', href);
            a.attr('onclick', 'return false;');
            a.append('&#9673; ' + ret.body.images[i].image_name);
            delete_div.click(function(){
                id          = delete_div_id;
                id_array    = id.split('_');
                $.post('files/delete', { id: image_id, del: id_array[1] }, function(data){
                    $(body).remove();
                });
            });
            body.append(a);
            body.append(delete_div);
            $('#' + parent).children().eq(1).append(body);
            $('.lightbox').colorbox({rel: 'group1'});
        }
    
        footer = $('<a>').addClass(ret.footer['attr'].class).attr('id', ret.footer['attr'].id).attr('href', ret.footer['href']);
        footer.append(ret.footer['text']);
        footer.click(function(e){
            e.preventDefault();
            e.stopPropagation();
            $.colorbox({href: ret.footer['href']});
        });
        $('#' + parent).children().eq(2).html(footer);
    }
    

    Explanation :
    the first code i had the creation of the elements happens globally so every time the code executes it overwrite the variables and i’m assigning the the colorbox to the click function here:

    footer.click(function(e){
        e.preventDefault();
        e.stopPropagation();
        $.colorbox({href: ret.footer['href']});
    });
    

    so every time the footer variable gets rewritten over that click gets reassigned to the new footer that’s why colorbox sends the data to the wrong url so all i have to do is to make those variables local to a function in this case the swap_content() function now each footer is unique and therefore colorbox will send the data to the right url.
    thanks for those who tried to answer.
    hope this helps anyone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple UpdatePanels on a webpage, one inside UserControl (Purple ColorBox as show
I have multiple links in my page rendered from the database. All of them
I have multiple instances of <div class=picOuterDiv> <a href=examplepage.php?var=1 class=iframe > page one </a>
I have multiple charts in one page but I am getting this error when
I have multiple input fields on one page. Each input field have a text
I have multiple arrays in javascript and I want to do sum of those
I have multiple plone sites in one zope instance (ZODB). Now I'd like to
I have multiple ajax requests with javascript code as response, and I need to
I have multiple forms for lots of products on my page and want to
I have multiple input fields on my page. I Regex them with a css

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.