We had a very similar discussion on a thread last week:
http://www.nabble.com/How-to-convert-%22class%22-to-%22style%3D%27attrs-...%27%22-tf3409582.html
The code you want would be similar to:
function isStyled(className){
var re = new RegExp('(^|,)\\s*\\.'+className+'\\s*(\\,|$)');
var ret = false;
$.each (document.styleSheets, function(){
$.each (this.cssRules || this.rules, function() {
if (re.test(this.selectorText)) ret = true;
});
});
return ret;
}
Returns true if ".className" is used as a selector in any style sheet
Danny
Erik Beeson wrote:
>
> Sounds like you're looking for something like "has a class with this name
> been defined". As far as I know, such a concept doesn't exist. But I think
> your approach is flawed. Instead of trying to only define a style if it
> didn't exist, I think you want to define the defaults first, then allow
> other styles to override them.
>
> --Erik
>
>
> On 3/16/07, Daemach <[EMAIL PROTECTED]> wrote:
>>
>> Agreed. The issue is that I don't want to override a stylesheet rule if
>> it exists already for this element.
>>
>> > >> Daemach wrote:
>> > >> >
>> > >> > I'm working on something that I want a user to be able to override
>> > by
>> > >> > including a specific class somewhere in the CSS definitions. If
>> > that
>> > >> > class
>> > >> > doesn't exist I want to add a default style. This seems like
>> > something
>> > >> > that
>> > >> > should have come up before but search isn't coming up with
>> > >> anything. Can
>> > >> > someone point me in the right direction? Local styles/classes
>> > override
>> > >> > global classes right?
>> > >> >
>> > >> > IOW given the following:
>> > >> >
>> > >> > <style>
>> > >> > #myDiv {background: blue;}
>> > >> > </style>
>> > >> >
>> > >> > <div id="myDiv" style="background: red">
>> > >> >
>> > >> > The div's background would be red, correct?
>
>
--
View this message in context:
http://www.nabble.com/How-can-I-find-out-if-a-%3Cstyle%3E-class-exists--tf3416167.html#a9550436
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/