Click to See Complete Forum and Search --> : Attempting to use JavaScript-Based Style Sheets


theekx
09-15-2003, 02:10 PM
Does MSIE support JSSS? I want to have one external style sheet where i can use variables to control the different style and color. It looked like JSSS was the only way that I could accomplish this!

Thanks for helping me

DaveSW
09-15-2003, 02:41 PM
I'm guessing yes, because I've seen some encryption software somewhere that used css stylesheets encrypted in a jevascript file.

However, your stylesheets won't be supported by the 13% of people who have javascript disabled.

theekx
09-15-2003, 02:47 PM
I am questioning this because I attempted to use document.tags.h1.color="blue" and I received a java script error telling me that tags was not defined.

Any ideas?

DaveSW
09-15-2003, 02:53 PM
you're more likely to find someone with the knowledge you require in javascript forum, so I'll move this thread there if this doesn't work:

Why don't you use document.write to add in a style declaration, tailored to what you want in javascript, to the top of every page?

theekx
09-15-2003, 02:58 PM
Please move this thread to the javascript forum.

Thanks.

DaveSW
09-15-2003, 03:01 PM
No Problem

Jona
09-15-2003, 03:06 PM
Originally posted by theekx
I am questioning this because I attempted to use document.tags.h1.color="blue" and I received a java script error telling me that tags was not defined.

That code does not work for two reasons. First, document.tags returns "undefined" since there is no tags object existent, and secondly because There is no attribute "color" in the tag <h1>. You must use style.color. This should work for you, assuming you are trying to edit the first H1 tag in the document:


document.getElementsByTagName("h1")[0].style.color="blue";


[J]ona

theekx
09-15-2003, 03:16 PM
What would I do if I wanted to change all H1 tags in my web page?

Thanks.

Jona
09-15-2003, 03:18 PM
Originally posted by theekx
What would I do if I wanted to change all H1 tags in my web page?

You'd use a for() loop...


for(i=0; i<document.getElementsByTagName("h1").length; i++){
document.getElementsByTagName("h1")[i].style.color="blue";
}


[J]ona

theekx
09-15-2003, 03:23 PM
Jona,

Thanks you for you help!


It looks like IE does not support Javascript-Based Style Sheets. The following site must pertain to NS only:

http://developer.netscape.com/docs/manuals/jsstyles_real.html

Jona
09-15-2003, 03:28 PM
What you refer to appears to be deprecated, so I doubt the code you've posted (or the code at the site to which you linked) would work in any browser, other than older ones...

[J]ona

theekx
09-16-2003, 09:11 AM
Thank you Jona. I will throw it in the trash and come up with something else.

Jona
09-16-2003, 11:56 AM
Originally posted by theekx
Thank you Jona. I will throw it in the trash and come up with something else.

The code I posted should work perfectly. Is there something else you are trying to do?

[J]ona