0

I have the next two elements on an HTML file:

<a id="a1" href="?cssfile=css-folder/015/styles.css">Style number 015</a>
<div id="a1Preview"></div>

The first one (anchor) is a reference to a CSS that will be loaded dynamically by the page. The second one (div) pretends to be a preview (thumbnail) of the style sheet.

THE PROBLEM IS I need a way to set the div background dynamically from the CSS, something like:

#a1Preview
{
    background: url(css-folder/{"015" extracted from the <a> element}/preview.png);
}

Is this possible? Any ideas? Of course the HTML is untouchable. I can only change the CSS.

Thanks in advance.

2
  • 1
    Unfortunately, it's not possible with pure CSS. You're going to have to fall back to scripting for this, assuming you can use a script. Commented Jan 10, 2012 at 18:05
  • As far as I know it's not possible to trigger script from CSS, am I right? I can only work on the CSS file. Any chance to do it from there? Commented Jan 10, 2012 at 18:08

1 Answer 1

1

You could use jQuery to change the css content dynamically. jQuery is a extension to javascript. From there you could then use the system you use to skin, but generally to extract href attributes from tags and change CSS, you can use such a thing.

Sign up to request clarification or add additional context in comments.

2 Comments

Is jQuery available in any form for my CSS file? I can only work on the CSS file.
If you can't touch the CSS file and you are working on a project, then maybe ask the developer(s) to implement a system with this library, overall their code may be minimised or they may have a better system using jQuery, but as far as I can see-- jQuery is the only way (not unless you want to make a style for each item, which seems the longer way round)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.