From: Steve on
Anyone have an example of getting and setting an attribute of a CSS
class defined at the top of an HTML page?

Thanks in advance

From: Jonathan N. Little on
Steve wrote:
> Anyone have an example of getting and setting an attribute of a CSS
> class defined at the top of an HTML page?

Do you mean via JavaScript? Or do you mean inserting a STYLE element
within the HEAD?

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
From: Steve on


Jonathan N. Little wrote:
> Steve wrote:
> > Anyone have an example of getting and setting an attribute of a CSS
> > class defined at the top of an HTML page?
>
> Do you mean via JavaScript? Or do you mean inserting a STYLE element
> within the HEAD?

Setting it up in the HEAD and then using javascript to alter it
dynamically.
From: Jonathan N. Little on
Steve wrote:
>
> Jonathan N. Little wrote:
>> Steve wrote:
>>> Anyone have an example of getting and setting an attribute of a CSS
>>> class defined at the top of an HTML page?
>> Do you mean via JavaScript? Or do you mean inserting a STYLE element
>> within the HEAD?
>
> Setting it up in the HEAD and then using javascript to alter it
> dynamically.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-language" content="en-us">

<title>template</title>

<style type="text/css">
#theTarget { color: black; background-color: white; }
</style>

<script type="text/javascript">
function killTarget (){
var t=document.getElementById('theTarget');
t.style.color="red";
t.style.backgroundColor="#aaa";
}

</script>

</head>
<body>
<p><a href="#" onclick="killTarget()">Click Me</a> to shoot the <span
id="theTarget"> target </span></p>
</body>
</html>


--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
From: Jeff on
Jonathan N. Little wrote:
> Steve wrote:
>>
>> Jonathan N. Little wrote:
>>> Steve wrote:
>>>> Anyone have an example of getting and setting an attribute of a CSS
>>>> class defined at the top of an HTML page?
>>> Do you mean via JavaScript? Or do you mean inserting a STYLE element
>>> within the HEAD?
>>
>> Setting it up in the HEAD and then using javascript to alter it
>> dynamically.

The question is still nebulous.

Jonathans "solution" will not change all elements of a particular class.
If the OP wishes to do that he should look into addRule and insertRule,
I don't remember which is IE and and which is everyone else. Those work
with any selector, not just class names. I think the OP is unsure of
what he wants.

Jeff
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">
> <html>
> <head>
> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
> <meta http-equiv="content-language" content="en-us">
>
> <title>template</title>
>
> <style type="text/css">
> #theTarget { color: black; background-color: white; }
> </style>
>
> <script type="text/javascript">
> function killTarget (){
> var t=document.getElementById('theTarget');
> t.style.color="red";
> t.style.backgroundColor="#aaa";
> }
>
> </script>
>
> </head>
> <body>
> <p><a href="#" onclick="killTarget()">Click Me</a> to shoot the <span
> id="theTarget"> target </span></p>
> </body>
> </html>
>
>