views:

35

answers:

2

I am using Colorbox 1.3.6 with jQuery 1.4.2. Somehow the folowing code did not work for me:

$(document).ready(function() {
    $.colorbox({href: "something.htm", open: true});
});

which won't show up automatically, but this one works:

$(document).ready(function() {
    $("#some_element").colorbox({href: "something.htm", open: true});
});

I tried attaching to $("head") which also works! And then I checked the generated elements, it seems that colorbox just added class="cboxElement" to head element and other things all in the body.

But I do not sure if this is a good way to do it (auto popup when the page is loaded) and I can't figure out why $.colorbox did not work!

Please help!

A: 

To be honest, I have used ColorBox before in the same method with successful results. I'm unsure why it wouldn't work as you have it set up.

Since jQuery was updated from 1.4.1 to 1.4.2, apparently a lot of different plugins have had issues with it. I do not know if ColorBox has been proven to work perfectly with 1.4.2. You could always try to download 1.4.1 to give a try. That could be the problem.

BigRossLabs
The colorbox plugin example pages all use jQuery 1.4.2, so I doubt this is the issue :) http://colorpowered.com/colorbox/core/example1/index.html
Nick Craver
@BigRossLabs,Thanks for your answer!But I think it is not very safe to downgrade because there are other plugins and I am afraid downgrading would cause other problems.@Nick Craver,In the colorbox plugin example page, all those examples are $("something") but not $.colorbox which stated in the homepage's instruction http://colorpowered.com/colorbox/Anyway, thx a lot!
PeterWong
A: 

The problem is that the documentation you're seeing is for a newer version, not 1.3.6 that you're using. To do what you want with 1.3.6, try this instead this:

$(function() {
  $.fn.colorbox({href: "something.htm", open: true});
});

If you look at version 1.3.6, you'll see this in the source:

cboxPublic = $.fn.colorbox = function (options, callback) {

It's not until this commit for 1.3.7 that $.colorbox shows up:

cboxPublic = $.fn.colorbox = $.colorbox = function (options, callback) {

So $.colorbox() does work...but only for version 1.3.7+, as of the time of this answer the current version is 1.3.9, so if you want to use $.colorbox() instead of $.fn.colorbox() just upgrade :)

Nick Craver