473,474 Members | 1,682 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: Storing style properties aside from object

vunet wrote:
[...] I was thinking about something like:

var style1 = {
backgroundColor:"blue",
color:"white"
}

var myDiv = document.createElement("div");
myDiv.style = style1;

The question is how correct that is
It is not correct at all. The `style' property is specified to be read-only:

<http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-ElementCSSInlineStyle>
and/or is there a better way to do it?
if (myDiv)
{
for (var p in style1)
{
if (typeof myDiv.style[p] != "undefined")
{
myDiv.style[p] = style1[p];
}
}
}

See <http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties>.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Sep 10 '08 #1
1 921
On Sep 10, 1:53*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
vunet wrote:
[...] I was thinking about something like:
var style1 = {
backgroundColor:"blue",
color:"white"
}
var myDiv = document.createElement("div");
myDiv.style = style1;
The question is how correct that is

It is not correct at all. *The `style' property is specified to be read-only:

<http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-ElementCSSInlineS...>
and/or is there a better way to do it?

* if (myDiv)
* {
* * for (var p in style1)
* * {
* * * if (typeof myDiv.style[p] != "undefined")
* * * {
* * * * myDiv.style[p] = style1[p];
* * * }
* * }
* }

See <http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties>.

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Thank you
Sep 10 '08 #2

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

Similar topics

12
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
9
by: JimO | last post by:
I'm a newbie at this and I can't seem to find a list properties names to change styles on the fly. So far I've been lucky and managed to guess the names such as BodyElement.style.marginTop = 0;...
4
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView...
10
by: Mark Rae | last post by:
Hi, This relates to the previous thread "Disappearing Sessions", but is a bit more generic so I thought I'd start a new thread. This one relates to the storing of objects in Session once only to...
8
by: psema4 | last post by:
Hi all, I've spent several days trying to work this out. Maybe I'm just searching for the wrong keywords/phrases. I have some code that looks like: Console = new Object(); Console.init...
2
by: Paul Hadfield | last post by:
Hi, I'm not having a lot of luck googling for this one, I want to be able to store a custom class in the user settings (DotNet2.0, win app). I don't wish to create public get / set properities...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
5
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...
4
by: Nathan Sokalski | last post by:
I have a content page from which I need to add a style rule to be used by the page. Since content pages only have the content tags, I obviously need to edit the Master page's style using code. I am...
0
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,...
0
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...
0
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.