I don't think jQuery is designed to get an attribute from a class.
The code you wrote

<div class="myclass" />
...
var color = $(".myclass").css("background-color");

works by pulling the background color from the DOM object.  A
different hack that would work in one line:

$('<div></div>').addClass('myclass').css('background-color');

That would create a div, add a class to it, and fetch the background
color.


On Nov 26, 4:40 pm, Craig <[EMAIL PROTECTED]> wrote:
> Hi, does anyone know if it's possible to extract a style attribute
> from a style (and not an element)?
> For instance:
> <style>
> .myclass { background-color:white; }
> </style>
>
> I have some legacy javascript that takes colors as parameters to
> functions and i'd like to be able to define those in a style sheet and
> then 'extract' the colors from that.
>
> I can only get it to work if I do something like this:
> <div class="myclass" />
> ...
> var color = $(".myclass").css("background-color");
>
> any ideas?
> Craig.

Reply via email to