473,785 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HOW TO: Create Style/Class Elements Programmaticall y

gsb
Is there a way to create, say createElement( "STYLE"), to create new classes
or style sheets from within JavaScript?

Thanks,

gsb
Jul 20 '05 #1
7 8232
gsb wrote:
Is there a way to create, say createElement( "STYLE"), to create new classes
or style sheets from within JavaScript?
Yes.
Thanks,


Welcome.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/

Jul 20 '05 #2
DU
gsb wrote:
Is there a way to create, say createElement( "STYLE"), to create new classes
or style sheets from within JavaScript?

Thanks,

gsb

To create a new stylesheet:

var AccessibilitySt yleSheet = document.create StyleSheet("Acc essibility
style sheet", "projection,scr een,tv");
For the general syntax, see:
http://www.w3.org/TR/2000/REC-DOM-Le...eCSSStyleSheet
To populate that stylesheet:

AccessibilitySt yleSheet.insert Rule("p {color:green; font-size:120%}", 0);
AccessibilitySt yleSheet.insert Rule("div.someC lassName
{background-color:blue}", 1);

For the general syntax, see:
http://www.w3.org/TR/2000/REC-DOM-Le...eet-insertRule

The methods given are standard W3C DOM 2 CSS methods. You should expect
only recent browsers (like Mozilla 1.5+, Opera 7.5, Safari 1.2,
Konqueror 3.2) to support these W3C methods: untested and unverified.
MSIE uses different methods.

DU
Jul 20 '05 #3


gsb wrote:
Is there a way to create, say createElement( "STYLE"), to create new classes
or style sheets from within JavaScript?


Have a look at
http://groups.google.com/groups?q=ad...ine.net&rnum=4

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #4
DU
DU wrote:
gsb wrote:
Is there a way to create, say createElement( "STYLE"), to create new
classes
or style sheets from within JavaScript?

Thanks,

gsb

To create a new stylesheet:

var AccessibilitySt yleSheet = document.create StyleSheet("Acc essibility
style sheet", "projection,scr een,tv");


It should have been written rather

var AccessibilitySt yleSheet =
document.create CSSStyleSheet(" Accessibility style sheet",
"projection,scr een,tv");

As far as I know, currently no browser support createCSSStyleS heet.

document.implem entation.create CSSStyleSheet() Not Implemented
http://bugzilla.mozilla.org/show_bug.cgi?id=63850
For the general syntax, see:
http://www.w3.org/TR/2000/REC-DOM-Le...eCSSStyleSheet

To populate that stylesheet:

AccessibilitySt yleSheet.insert Rule("p {color:green; font-size:120%}", 0);
AccessibilitySt yleSheet.insert Rule("div.someC lassName
{background-color:blue}", 1);

document.styleS heets[0].insertRule("p {color:green; font-size:120%}", 1);
document.styleS heets[0].insertRule("di v.someClassName
{background-color:blue}", 1);

will work in Mozilla-based browsers.

DU
For the general syntax, see:
http://www.w3.org/TR/2000/REC-DOM-Le...eet-insertRule
The methods given are standard W3C DOM 2 CSS methods. You should expect
only recent browsers (like Mozilla 1.5+, Opera 7.5, Safari 1.2,
Konqueror 3.2) to support these W3C methods: untested and unverified.
MSIE uses different methods.

DU

Jul 20 '05 #5


DU wrote:
DU wrote:
gsb wrote:
Is there a way to create, say createElement( "STYLE"), to create new
classes
or style sheets from within JavaScript?


To create a new stylesheet:

var AccessibilitySt yleSheet = document.create StyleSheet("Acc essibility
style sheet", "projection,scr een,tv");

It should have been written rather

var AccessibilitySt yleSheet =
document.create CSSStyleSheet(" Accessibility style sheet",
"projection,scr een,tv");


No, it should be
document.implem entation.create CSSStyleSheet(. .., ...)
but that is not supported by Mozilla or other browsers and wouldn't help
as the DOM spec itself admits that there is no way to associate the
created stylesheet with a document.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #6
gsb
Thanks all.
Looks like I can get it to work.

gsb

"gsb" <gs*@QWest.ne t> wrote in message
news:f5******** *********@news. uswest.net...
Is there a way to create, say createElement( "STYLE"), to create new classes or style sheets from within JavaScript?

Thanks,

gsb

Jul 20 '05 #7
On Thu, 19 Feb 2004 09:17:11 -0800, gsb wrote:
Thanks all.
Looks like I can get it to work.

gsb


Hi,

I am curious... and late to thsi thread...

What was the scenario for generating style data dynamically?

Thx
DK

Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12184
by: David Bradbury | last post by:
I may be thinking about this the wrong way, but here goes: In my style sheet I've specified that bullet points should use a specific image rather than just be default bullet points. However, at some later point in the text I don't want to use the bullet point with an image, but rather use the standard bullet point. Is it possible to switch off a style sheet instruction for an individual instance? Or do I need to define a new style...
21
3991
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does nothing in IE. I'd be greatful for any assistance. Also, if I will have problems the code on Opera or Safari, I'd appreciate any pointers--I don't have a Mac to test Safari. THanks very much, Michael
3
5821
by: charley | last post by:
Hello, The appearance of the page should be for the main image, lpmap.jpg, to be on the bottom, (z-index: 1), with pictures, (image0.jpg - image9.jpg), and accompaning notes to appear on top, (z-index: 2), minimized to 20px x 20px width & height, using the box model. These 10, (point0 to point9), are positioned on the map with the position style. These small images should then enlarge when the mouse hovers over them, (z-index: 3).
3
16506
by: Waffeloo | last post by:
Hi, I would like an event to trigger a change the style of all the elements that belong to some CSS class. I know it is possible to change the class of an element, for example with: <script language=javascript> function changeclass() {document.getElementById(id).className="class_id";} </script> <input type=checkbox onclick="javascript:changeclass()">
2
1689
by: davidw | last post by:
As I asked in last post, I want to put some logic in a object and all my webcontrol instance will access that object, the object is responsed to retrieve data from database if the data has not been retrieved yet. Vadym Stetsyak suggested me to use singleton, it seems a good solution for me, but after I read more about singleton, I find another issue - if I use singleton patter, I can not store context data in the class anymore. How I used...
5
1681
by: JezB | last post by:
Is it possible to programatically examine and modify a page's Styles (including Cascading Style Sheets) within the code-behind-module (eg. c#) ? My guess is that since these are HTML elements the answer is no, since these will only exist in the browser whereas the code-behind runs on the web server, but I wanted verification from you experts out there (I'm new to ASP.NET). If the answer is no, is it possible via javascript ?
7
4335
by: MarkoH | last post by:
Wsdl.exe /server creates abstract class derived from WebService. Is there a way to create this class at runtime based on some WSDL file given at runtime ? What would be even better - creating concrete class but with empty method implementation of course since WSDL does not provide any info on implementation. Thanks M.
4
8284
by: sirjohnofthewest | last post by:
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man. Hi guys, I frequently visit this site to get answers to my problems and this one is really getting to me... I have a page that allows you to Browse Authors. There are three drop down boxes that auto-populate via AJAX. I have a file which it calls and returns the dynamically built XML file in the boxes...
5
3752
by: Nathan Sokalski | last post by:
I have css that would normally be placed in style tags in the header of the Master page that I want to add programmatically for a specific Web Content Form (the *.aspx page). How do I do this for a Web Content Form? I cannot use style tags in a Web Content Form, and I am having trouble figuring out how to add all the desired css properties to a System.Web.UI.WebControls.Style object. Can anyone help me? Thanks. -- Nathan Sokalski...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.