Question

Trying to do the following: my page has got a lot of div's with 's to open modalboxes (colorbox). The pages that these links open got an id="mainColumn". Content need only to be loaded from this id.

I've got this:

<div>                       
<a href="includes/page_1.html" class="modal"></a>
</div>

<div>                       
<a href="includes/page_2.html" class="modal"></a>
</div>

<div>                       
<a href="includes/page_3.html" class="modal"></a>
</div>


 $(".modal").colorbox({
    width:900,
    href: $(".modal").attr('href') + " #mainColumn"
    });

It works great... Except that the href's of al of the 's change into the first one...

So includes/page_3.html changes into includes/page_1.html or in other words: All of the modalboxes show the same content...

any help would appreciated, thanks

Was it helpful?

Solution 2

$(".pop").each(function() {
  var el = $(this);
  el.colorbox({
    href: el.attr('href') + " #mainColumn"
  });
});

OTHER TIPS

use $(this) to get the current (clicked) one

$(".modal").colorbox({
    width:900,
    href: $(this).attr('href') + " #mainColumn"
});

You could do this:

$(".modal").colorbox({
    width:900,
    href: function(){ return $(this).attr('href') + " #mainColumn"; }
});

Or this:

$(".modal").each(function(){
    $(this).colorbox({
        width:900,
        href: $(this).attr('href') + " #mainColumn"
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top