[jQuery] Re: style selector (noob question)

2008-11-26 Thread Craig

Thanks! That looks to be just the solution I'm looking for.

On Nov 27, 1:10 pm, seasoup <[EMAIL PROTECTED]> wrote:
> ok, found a plugin for you:
>
> http://flesler.webs.com/jQuery.Rule/
>
> 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:
> > 
> > .myclass { background-color:white; }
> > 
>
> > 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:
> > 
> > ...
> > var color = $(".myclass").css("background-color");
>
> > any ideas?
> > Craig.- Hide quoted text -
>
> - Show quoted text -


[jQuery] Re: style selector (noob question)

2008-11-26 Thread seasoup

ok, found a plugin for you:

http://flesler.webs.com/jQuery.Rule/



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:
> 
> .myclass { background-color:white; }
> 
>
> 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:
> 
> ...
> var color = $(".myclass").css("background-color");
>
> any ideas?
> Craig.


[jQuery] Re: style selector (noob question)

2008-11-26 Thread seasoup

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


...
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:

$('').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:
> 
> .myclass { background-color:white; }
> 
>
> 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:
> 
> ...
> var color = $(".myclass").css("background-color");
>
> any ideas?
> Craig.


[jQuery] Re: style selector (noob question)

2008-11-26 Thread ricardobeat

You could access the CSS rules via document.stylesheets[x].cssRules
[x].style.color, for example, but cross-browser support is not very
good:

http://www.quirksmode.org/dom/w3c_css.html

- ricardo

On Nov 26, 10: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:
> 
> .myclass { background-color:white; }
> 
>
> 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:
> 
> ...
> var color = $(".myclass").css("background-color");
>
> any ideas?
> Craig.


[jQuery] Re: style selector (noob question)

2008-11-26 Thread donb

I don't think there's anyway to directly reference what's in a style
declaration, only indirectly through an html element (as you found).
However, you could temporarily create an element, assign the class of
interest to it, and work with that.  Of course, you probably want to
'learn' what classes are defined so you know what to assign to the
temp element, which gets you nowhere because there's no way to read
the style information (that I know of).

On Nov 26, 7: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:
> 
> .myclass { background-color:white; }
> 
>
> 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:
> 
> ...
> var color = $(".myclass").css("background-color");
>
> any ideas?
> Craig.