473,396 Members | 2,154 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.

when do I need getPropertyValue()?

Hi,

Since I can do this

document.defaultView.getComputedStyle(el, null).height;

why would I ever want to do this

document.defaultView.getComputedStyle(el,
null).getPropertyValue('height');

Is there a browser with getComputedStyle() that cannot do the first way
and hence requires the use of getPropertyValue()?

Thank you,
Peter

Nov 24 '06 #1
3 6997
VK

Peter Michaux wrote:
Hi,

Since I can do this

document.defaultView.getComputedStyle(el, null).height;

why would I ever want to do this

document.defaultView.getComputedStyle(el,
null).getPropertyValue('height');
The first syntax requires property name in camelCase; the second syntax
takes property name as it is. This way it could be possible to choose
the most convenient way for a particular situation w/o normalizing all
involved names. But as IE currentStyle takes only camelCase anyway, the
second syntax didn't go into wide use.
Also please note that as you are asking for *computed* (current) style,
you are getting normalized value back (how is it internally stored by
UA, so not necessarily how it is indicated in the source). For the
second reason the whole getComputedStyle interface is used only rather
occasionally for specific tasks - yet for these tasks it is very
useful.

// See the sample:

<html>
<head>
<title>Styles</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
color: #000000;
background-color: #FFFFFF;
}
h1 {
background-color: yellow;
}
</style>
<script type="text/javascript">
function init() {
var header = document.getElementsByTagName('h1')[0];
if ((document.defaultView)
&& (document.defaultView.getComputedStyle)) {
window.alert(document.defaultView
.getComputedStyle(header,null).backgroundColor);
window.alert(document.defaultView
.getComputedStyle(header,null)
.getPropertyValue('background-color'));
}
else if (header.currentStyle) {
window.alert(header.currentStyle.backgroundColor);
}
}
window.onload = init;
</script>
</head>
<body>
<h1>Lorem ipsum</h1>
</body>
</html>

Nov 24 '06 #2
VK

VK wrote:
Also please note that as you are asking for *computed* (current) style,
you are getting normalized value back (how is it internally stored by
UA, so not necessarily how it is indicated in the source). For the
second reason the whole getComputedStyle interface is used only rather
occasionally for specific tasks - yet for these tasks it is very
useful.
To not be abstract: getComputedStyle can be used to determine the exact
pixel size of 1em for the given font on the given machine.

Nov 24 '06 #3
Hi VK,

VK wrote:
Peter Michaux wrote:
Hi,

Since I can do this

document.defaultView.getComputedStyle(el, null).height;

why would I ever want to do this

document.defaultView.getComputedStyle(el,
null).getPropertyValue('height');

The first syntax requires property name in camelCase; the second syntax
takes property name as it is. This way it could be possible to choose
the most convenient way for a particular situation w/o normalizing all
involved names. But as IE currentStyle takes only camelCase anyway, the
second syntax didn't go into wide use.
So other than hyphenated vs. camelCase is there any difference. Does
anyone know of a browser bug surrounding this issue where
getPropertyValue() is the only solution? I would much prefer to use the
first with it's camelCase property.

Thanks,
Peter

Nov 25 '06 #4

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

Similar topics

3
by: Jack Black | last post by:
Using Mozilla 1.4... I need to get the Height and Width of an object (in this case, a parent DIV) for the purpose of creating a textbox of max width and height in the container. Since...
6
by: Louise | last post by:
Hi I have written an HTML pages which does not have any colour specifying tags as far I know. When I view this in an Microsoft internet explorer browser it appears with a white background and...
26
by: Simon | last post by:
I'm doing a survey. When do you think GNU/Linux will be ready for the average Joe? What obstacles must it overcome first?
22
by: Bradley | last post by:
Has anyone else noticed this problem? I converted the back-end to A2000 and the performance problem was fixed. We supply a 97 and 2000 version of our software so we kept the backend in A97 to make...
6
by: Nathan Sokalski | last post by:
I am using a DataSet as the DataSource of a DataList in my code. The SQL used to get the data from the database begins with: SELECT...
2
by: Pugi! | last post by:
I would like to obtain the the position of backgroundimage of a div because I use it for animation. The following code works for Internet Explorer (takes the else if) and returns positionx '10px'...
44
by: Smokey Grindle | last post by:
I have a list box on my form, but I need to databind it to a data table that is a private member of the form's class... so I basically have Public Class MyForm priate m_MyTable as new datatable...
15
by: Jess | last post by:
Hello, Sometimes declarations are all what we need when we define/declare classes (or functions?), but sometimes we need definitions. I learned that if we define a class (B) that has an object...
0
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
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,...
0
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...

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.