views:

27

answers:

1

Hey!

I have a Lightbox clone (colorbox), which works fine and has no real issues. What I would like is an extra arguement that would say:

[pseudocode]

if (linksRel == "lightbox1") {
  add stylesheet1 to this lightbox
} else {
  add stylesheet2 to this lightbox
}

[/pseudocode]

Currently, I have a page with a "colorbox.css" file attached and the" jquery.colorbox.js" file as well - But I want the JS file to import the required CSS dependant on what link was clicked... Urgh, does that make sense?

Does anyone have any ideas? I'm stumped!

+1  A: 

You could try importing the stylesheet with jQuery like this:

$("#stylesheets").html('<link rel="stylesheet" href="style1.css" \/>');

using of course some kind of click() handler on that link you want.

stagas
Hey, this looks like the code I need. However, I have added a function that is called on click but the stylesheet isn't being added to the page. Where does the #stylesheets ID come in?
Neurofluxation
#stylesheets should be the ID of a div in your HTML where the stylesheets would be inserted into. In this case you need a `<div id="stylesheets" style="display:none;"></div>`
stagas
@Neurofluxation: Also make sure you test that on a few browsers, some might not accept that kind of behaviour (adding stylesheets on the fly with JS). If the answer was helpful you can Vote Up / Accept it.
stagas
Sorry, bit slow today.
Neurofluxation