473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Cascade problem with DOM & CSS?

Hello

consider:
<html>
<head>
<style type="text/css">
body{margin:50px;}
</style>
....
<body> ...

When i get a handle for the body (using DOM: doc.getElsByTagName ...
item(0))
and i try to read style.margin from the body, i get an empty string

However, when i specify the style info directly in the BODY element <body
style="margin:50px;"> , and then i read out style.margin ... i get my value
50px

? i dont know how the parsers work but after specifying style info whichever
way, is should be available in the object model shouldnt it???

Aparently both ie and ns behave the same on this ...

Ultimately i want to position elements absolutely but 'offsetLeft/Top'
doesnt relate to 'margin'

PIeter.
Jul 20 '05 #1
4 1366
Pieter Van Waeyenberge wrote:

Do currentStyle (IE) and getComputedStyle (NS/Moz) help you out?

--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Jul 20 '05 #2


Pieter Van Waeyenberge wrote:
consider:
<html>
<head>
<style type="text/css">
body{margin:50px;}
</style>
...
<body> ...

When i get a handle for the body (using DOM: doc.getElsByTagName ...
item(0))
and i try to read style.margin from the body, i get an empty string


Yes,
elementObject.style
only reflects what is set as an inline style (or later on with script),
it it not a cascaded or a computed style value.
IE provides
elementObject.currentStyle
W3C DOM compliant browsers like Mozilla or Opera 7 have
window.getComputedStyle(elementObject,
'').getPropertyValue('css-property-name')

--

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

Jul 20 '05 #3
thnx!

Pieter

"Pieter Van Waeyenberge" <p@foo.com> wrote in message
news:40*********************@news.skynet.be...
Hello

consider:
<html>
<head>
<style type="text/css">
body{margin:50px;}
</style>
...
<body> ...

When i get a handle for the body (using DOM: doc.getElsByTagName ...
item(0))
and i try to read style.margin from the body, i get an empty string

However, when i specify the style info directly in the BODY element <body
style="margin:50px;"> , and then i read out style.margin ... i get my value 50px

? i dont know how the parsers work but after specifying style info whichever way, is should be available in the object model shouldnt it???

Aparently both ie and ns behave the same on this ...

Ultimately i want to position elements absolutely but 'offsetLeft/Top'
doesnt relate to 'margin'

PIeter.

Jul 20 '05 #4
DU
Pieter Van Waeyenberge wrote:
Hello

consider:
<html>
<head>
<style type="text/css">
body{margin:50px;}
</style>
...
<body> ...

When i get a handle for the body (using DOM: doc.getElsByTagName ...
item(0))
HTML documents only allow 1 body element. So, parsing the collection of
body nodes unneedlessly takes time to be executed. Just
document.body
access the body node immediately. Much more efficient that way.
and i try to read style.margin from the body, i get an empty string

However, when i specify the style info directly in the BODY element <body
style="margin:50px;"> , and then i read out style.margin ... i get my value
50px

? i dont know how the parsers work but after specifying style info whichever
way, is should be available in the object model shouldnt it???
There is nothing to parse really. Just to access.

Aparently both ie and ns behave the same on this ...

Ultimately i want to position elements absolutely but 'offsetLeft/Top'
doesnt relate to 'margin'
You'll need to take under consideration the borders on the root element
for MSIE 6 in standards compliant rendering mode and the padding on the
body for Opera 7.x

PIeter.

offsetLeft and offsetTop are DOM extensions and refer to MSIE's DHTML
object model. offsetLeft and offsetTop have not per se to do with css
rules, stylesheets, css properties.

Here's how to access the margin property values as set in a local
stylesheet (such stylesheet must be the only stylesheet, otherwise you
need to set the index accordingly: document.styleSheets[index])

if(document.styleSheets[0] && "cssRules" in document.styleSheets[0])
// DOM 2 Stylesheet compliant
{
alert("Margins on the body are: " +
document.styleSheets[0].cssRules[0].style.margin);
}
else if(document.styleSheets[0] && "rules" in document.styleSheets[0])
// MSIE
{
alert("Margins on the body are: " +
document.styleSheets[0].rules[0].style.margin);
};

getComputedStyle is good only when the margins have not been set or have
been modified dynamically by the user.

DU
Jul 20 '05 #5

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

Similar topics

0
by: Fraser Hanson | last post by:
Hello, I have a table which has a foreign key relationship with itself. I want and expect my updates to cascade (deletes definitely cascade as expected) but instead I just get error 1217:...
1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
2
by: Gunnar Vøyenli | last post by:
Hi! For the sake of simplicity, I have three tables, Employee, Department and Work Employee >---- Department \ / \ / ^ ^ Work
2
by: P.B. via SQLMonster.com | last post by:
I cannot execute my sql to create a table with ON DELETE CASCADE option. Here is my sql: CREATE TABLE Employees (Name Text(10) not null, Age number, CONSTRAINT pkEmployees PRIMARY KEY (Name)); ...
2
by: Jack | last post by:
We are have a question about the no cascade option on before triggers. The description stays that no other triggers will be fired by the changes of a before trigger. One of our developers is...
33
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and...
3
by: Tim Marshall | last post by:
HI all, Access 2003, Jet back end. Rather than annoy my users in a particular app by having relationships with enforced relational integrity refuse to delete a record with related records, I'm...
14
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where...
2
by: R.Welz | last post by:
Hello. I want to discuss a problem I have with my database design becourse I feel I cannot decide wheather I am on the right way of doing things. First of all, I am writing a literature and...
3
by: sonia.sardana | last post by:
Que-What is the use of CASCADE CONSTRAINTS? Ans-When this clause is used with the DROP command, a parent table can be dropped even when a child table exists. Example create table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
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...

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.