473,654 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access CSS with JavaScript

I have a css file this is a portion of it:

/* trackaccept.css */
div.track {
width:400px;
height: 100px;
}

I have this in my ASP page:

<link rel="stylesheet " type="text/css" href="/includes/trackaccept.css "/>

I need to read the values for width and height in my page. How do I acess those values using JavaScipt? Thanks.

I have a length of 2 for CSS objects so I don't know whether it is 0 or 1 I'm assuming 0.since I don't have any other external CSS statements. The other is declared in the page as <style></style>

--
George Hester
_______________ _______________ ____
Jul 20 '05 #1
11 15737


George Hester wrote:
I have a css file this is a portion of it:

/* trackaccept.css */ div.track { width:400px; height: 100px; }

I have this in my ASP page:

<link rel="stylesheet " type="text/css"
href="/includes/trackaccept.css "/>

I need to read the values for width and height in my page. How do I
acess those values using JavaScipt? Thanks.

I have a length of 2 for CSS objects so I don't know whether it is 0
or 1 I'm assuming 0.since I don't have any other external CSS
statements. The other is declared in the page as <style></style>


Whether you have
<link rel="stylesheet "
or
<style type="text/css">
doesn't matter, browsers like IE4+ or Netscape 6+ and Mozilla support a
document.styleS heets
collection where each sheet appears.
You can access the CSS rules in the stylesheets and read and change
value of properties in a rule, unfortunately different in IE and
Netscape. IE has
document.styleS heets[i].rules[i].style.width
Netscape
document.styleS heets[i].cssRules[i].style.width

Here is an example:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getStyleObject (styleSheetInde x, ruleIndex) {
if (document.style Sheets) {
var styleSheet = document.styleS heets[styleSheetIndex];
if (styleSheet) {
var rule;
if (styleSheet.css Rules) {
rule = styleSheet.cssR ules[ruleIndex];
}
else if (styleSheet.rul es) {
rule = styleSheet.rule s[ruleIndex];
}
if (rule && rule.style) {
return rule.style;
}
else {
return null;
}
}
else {
return null;
}
}
else {
return null;
}
}

function testStyleSheet () {
var style = getStyleObject( 0, 0);
if (style) {
alert('style.he ight: ' + style.height);
}
else {
alert('style not found.');
}
}
</script>
</head>
<body onload="testSty leSheet();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>

Note that even Opera 7 doesn't support document.styleS heets. And I don't
know about Safari or Konqueror support, does anyone else care to check
and contribute?

Of course with external style sheets make sure you use <body onload
before trying to access them.

You can also check the selector of a rule with selectorText:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getStyleObjectF romSelector (selectorText) {
if (document.style Sheets) {
for (var i = document.styleS heets.length - 1; i >= 0; i--) {
var styleSheet = document.styleS heets[i];
var rules;
if (styleSheet.css Rules) {
rules = styleSheet.cssR ules;
}
else if (styleSheet.rul es) {
rules = styleSheet.rule s;
}
if (rules) {
for (var j = rules.length - 1; j >= 0; j--) {
if (rules[j].selectorText == selectorText) {
return rules[j].style;
}
}
}
}
return null;
}
else {
return null;
}
}

function testStyleSheet () {
var selectors = ['#aDiv', '.someClass'];
for (var i = 0; i < selectors.lengt h; i++) {
var selector = selectors[i];
var style = getStyleObjectF romSelector(sel ector);
if (style) {
alert('Selector ' + selector + ': style.height: ' + style.height);
}
else {
alert('No rule found for selector ' + selector);
}
}
}
</script>
</head>
<body onload="testSty leSheet();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>
Of course if you are looking for the computed style of an object there
is no need to read through style sheet rules, getComputedStyl e allows
that with Mozilla and with Opera 7 and element.current Style with IE5+:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getComputedStyl eForElement (element, cssPropertyName ) {
if (element) {
if (window.getComp utedStyle) {
return window.getCompu tedStyle(elemen t,
'').getProperty Value(cssProper tyName.replace(/([A-Z])/g,
"-$1").toLowerCas e());
}
else if (element.curren tStyle) {
return element.current Style[cssPropertyName];
}
else {
return null;
}
}
else {
return null;
}
}

function getComputedStyl eForId (elementId, cssPropertyName ) {
if (document.getEl ementById) {
return
getComputedStyl eForElement(doc ument.getElemen tById(elementId ),
cssPropertyName );
}
else {
return null;
}
}

function testComputedSty le () {
var ids = ['aDiv', 'aP'];
for (var i = 0; i < ids.length; i++) {
var cssValue = getComputedStyl eForId(ids[i], 'backgroundColo r');
if (cssValue === null) {
alert('Style background-color for id ' + ids[i] + ' not found.');
}
else {
alert('Computed style for background-color for id ' + ids[i] + '
is ' + cssValue);
}
}
}
</script>
</head>
<body onload="testCom putedStyle();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>

Watch out for Netscape 7 and Opera 7 normalizing CSS values, for
instance color values are returned as rgb(r, g, b).
--

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

Jul 20 '05 #2
Oh Martin thanks for that.

--
George Hester
_______________ _______________ ____
"Martin Honnen" <ma*******@yaho o.de> wrote in message news:3f******** @olaf.komtel.ne t...


George Hester wrote:
I have a css file this is a portion of it:

/* trackaccept.css */ div.track { width:400px; height: 100px; }

I have this in my ASP page:

<link rel="stylesheet " type="text/css"
href="/includes/trackaccept.css "/>

I need to read the values for width and height in my page. How do I
acess those values using JavaScipt? Thanks.

I have a length of 2 for CSS objects so I don't know whether it is 0
or 1 I'm assuming 0.since I don't have any other external CSS
statements. The other is declared in the page as <style></style>


Whether you have
<link rel="stylesheet "
or
<style type="text/css">
doesn't matter, browsers like IE4+ or Netscape 6+ and Mozilla support a
document.styleS heets
collection where each sheet appears.
You can access the CSS rules in the stylesheets and read and change
value of properties in a rule, unfortunately different in IE and
Netscape. IE has
document.styleS heets[i].rules[i].style.width
Netscape
document.styleS heets[i].cssRules[i].style.width

Here is an example:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getStyleObject (styleSheetInde x, ruleIndex) {
if (document.style Sheets) {
var styleSheet = document.styleS heets[styleSheetIndex];
if (styleSheet) {
var rule;
if (styleSheet.css Rules) {
rule = styleSheet.cssR ules[ruleIndex];
}
else if (styleSheet.rul es) {
rule = styleSheet.rule s[ruleIndex];
}
if (rule && rule.style) {
return rule.style;
}
else {
return null;
}
}
else {
return null;
}
}
else {
return null;
}
}

function testStyleSheet () {
var style = getStyleObject( 0, 0);
if (style) {
alert('style.he ight: ' + style.height);
}
else {
alert('style not found.');
}
}
</script>
</head>
<body onload="testSty leSheet();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>

Note that even Opera 7 doesn't support document.styleS heets. And I don't
know about Safari or Konqueror support, does anyone else care to check
and contribute?

Of course with external style sheets make sure you use <body onload
before trying to access them.

You can also check the selector of a rule with selectorText:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getStyleObjectF romSelector (selectorText) {
if (document.style Sheets) {
for (var i = document.styleS heets.length - 1; i >= 0; i--) {
var styleSheet = document.styleS heets[i];
var rules;
if (styleSheet.css Rules) {
rules = styleSheet.cssR ules;
}
else if (styleSheet.rul es) {
rules = styleSheet.rule s;
}
if (rules) {
for (var j = rules.length - 1; j >= 0; j--) {
if (rules[j].selectorText == selectorText) {
return rules[j].style;
}
}
}
}
return null;
}
else {
return null;
}
}

function testStyleSheet () {
var selectors = ['#aDiv', '.someClass'];
for (var i = 0; i < selectors.lengt h; i++) {
var selector = selectors[i];
var style = getStyleObjectF romSelector(sel ector);
if (style) {
alert('Selector ' + selector + ': style.height: ' + style.height);
}
else {
alert('No rule found for selector ' + selector);
}
}
}
</script>
</head>
<body onload="testSty leSheet();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>


Of course if you are looking for the computed style of an object there
is no need to read through style sheet rules, getComputedStyl e allows
that with Mozilla and with Opera 7 and element.current Style with IE5+:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getComputedStyl eForElement (element, cssPropertyName ) {
if (element) {
if (window.getComp utedStyle) {
return window.getCompu tedStyle(elemen t,
'').getProperty Value(cssProper tyName.replace(/([A-Z])/g,
"-$1").toLowerCas e());
}
else if (element.curren tStyle) {
return element.current Style[cssPropertyName];
}
else {
return null;
}
}
else {
return null;
}
}

function getComputedStyl eForId (elementId, cssPropertyName ) {
if (document.getEl ementById) {
return
getComputedStyl eForElement(doc ument.getElemen tById(elementId ),
cssPropertyName );
}
else {
return null;
}
}

function testComputedSty le () {
var ids = ['aDiv', 'aP'];
for (var i = 0; i < ids.length; i++) {
var cssValue = getComputedStyl eForId(ids[i], 'backgroundColo r');
if (cssValue === null) {
alert('Style background-color for id ' + ids[i] + ' not found.');
}
else {
alert('Computed style for background-color for id ' + ids[i] + '
is ' + cssValue);
}
}
}
</script>
</head>
<body onload="testCom putedStyle();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>

Watch out for Netscape 7 and Opera 7 normalizing CSS values, for
instance color values are returned as rgb(r, g, b).
--

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

Jul 20 '05 #3
Hello again Matin. I tried the ComputedStyle one you gave. After fixing for line continuation issues in my newsreader I am getting undefined for both alerts. Is there something wrong with it? Here is what you had and what I put it to that is removing the line continuation issues.

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getComputedStyl eForElement (element, cssPropertyName ) {
if (element) {
if (window.getComp utedStyle) {
return window.getCompu tedStyle(elemen t,'').getProper tyValue(cssProp ertyName.replac e(/([A-Z])/g, "-$1").toLowerCas e());
}
else if (element.curren tStyle) {
return element.current Style[cssPropertyName];
}
else {
return null;
}
}
else {
return null;
}
}

function getComputedStyl eForId (elementId, cssPropertyName ) {
if (document.getEl ementById) {
return
getComputedStyl eForElement(doc ument.getElemen tById(elementId ), cssPropertyName );
}
else {
return null;
}
}

function testComputedSty le () {
var ids = ['aDiv', 'aP'];
for (var i = 0; i < ids.length; i++) {
var cssValue = getComputedStyl eForId(ids[i], 'backgroundColo r');
if (cssValue === null) {
alert('Style background-color for id ' + ids[i] + ' not found.');
}
else {
alert('Computed style for background-color for id ' + ids[i] + ' is ' + cssValue);
}
}
}
</script>
</head>
<body onload="testCom putedStyle();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>

--
George Hester
_______________ _______________ ____
"Martin Honnen" <ma*******@yaho o.de> wrote in message news:3f******** @olaf.komtel.ne t...


George Hester wrote:
I have a css file this is a portion of it:

/* trackaccept.css */ div.track { width:400px; height: 100px; }

I have this in my ASP page:

<link rel="stylesheet " type="text/css"
href="/includes/trackaccept.css "/>

I need to read the values for width and height in my page. How do I
acess those values using JavaScipt? Thanks.

I have a length of 2 for CSS objects so I don't know whether it is 0
or 1 I'm assuming 0.since I don't have any other external CSS
statements. The other is declared in the page as <style></style>


Whether you have
<link rel="stylesheet "
or
<style type="text/css">
doesn't matter, browsers like IE4+ or Netscape 6+ and Mozilla support a
document.styleS heets
collection where each sheet appears.
You can access the CSS rules in the stylesheets and read and change
value of properties in a rule, unfortunately different in IE and
Netscape. IE has
document.styleS heets[i].rules[i].style.width
Netscape
document.styleS heets[i].cssRules[i].style.width

Here is an example:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getStyleObject (styleSheetInde x, ruleIndex) {
if (document.style Sheets) {
var styleSheet = document.styleS heets[styleSheetIndex];
if (styleSheet) {
var rule;
if (styleSheet.css Rules) {
rule = styleSheet.cssR ules[ruleIndex];
}
else if (styleSheet.rul es) {
rule = styleSheet.rule s[ruleIndex];
}
if (rule && rule.style) {
return rule.style;
}
else {
return null;
}
}
else {
return null;
}
}
else {
return null;
}
}

function testStyleSheet () {
var style = getStyleObject( 0, 0);
if (style) {
alert('style.he ight: ' + style.height);
}
else {
alert('style not found.');
}
}
</script>
</head>
<body onload="testSty leSheet();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>

Note that even Opera 7 doesn't support document.styleS heets. And I don't
know about Safari or Konqueror support, does anyone else care to check
and contribute?

Of course with external style sheets make sure you use <body onload
before trying to access them.

You can also check the selector of a rule with selectorText:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getStyleObjectF romSelector (selectorText) {
if (document.style Sheets) {
for (var i = document.styleS heets.length - 1; i >= 0; i--) {
var styleSheet = document.styleS heets[i];
var rules;
if (styleSheet.css Rules) {
rules = styleSheet.cssR ules;
}
else if (styleSheet.rul es) {
rules = styleSheet.rule s;
}
if (rules) {
for (var j = rules.length - 1; j >= 0; j--) {
if (rules[j].selectorText == selectorText) {
return rules[j].style;
}
}
}
}
return null;
}
else {
return null;
}
}

function testStyleSheet () {
var selectors = ['#aDiv', '.someClass'];
for (var i = 0; i < selectors.lengt h; i++) {
var selector = selectors[i];
var style = getStyleObjectF romSelector(sel ector);
if (style) {
alert('Selector ' + selector + ': style.height: ' + style.height);
}
else {
alert('No rule found for selector ' + selector);
}
}
}
</script>
</head>
<body onload="testSty leSheet();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>


Of course if you are looking for the computed style of an object there
is no need to read through style sheet rules, getComputedStyl e allows
that with Mozilla and with Opera 7 and element.current Style with IE5+:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getComputedStyl eForElement (element, cssPropertyName ) {
if (element) {
if (window.getComp utedStyle) {
return window.getCompu tedStyle(elemen t,
'').getProperty Value(cssProper tyName.replace(/([A-Z])/g,
"-$1").toLowerCas e());
}
else if (element.curren tStyle) {
return element.current Style[cssPropertyName];
}
else {
return null;
}
}
else {
return null;
}
}

function getComputedStyl eForId (elementId, cssPropertyName ) {
if (document.getEl ementById) {
return
getComputedStyl eForElement(doc ument.getElemen tById(elementId ),
cssPropertyName );
}
else {
return null;
}
}

function testComputedSty le () {
var ids = ['aDiv', 'aP'];
for (var i = 0; i < ids.length; i++) {
var cssValue = getComputedStyl eForId(ids[i], 'backgroundColo r');
if (cssValue === null) {
alert('Style background-color for id ' + ids[i] + ' not found.');
}
else {
alert('Computed style for background-color for id ' + ids[i] + '
is ' + cssValue);
}
}
}
</script>
</head>
<body onload="testCom putedStyle();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>

Watch out for Netscape 7 and Opera 7 normalizing CSS values, for
instance color values are returned as rgb(r, g, b).
--

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

Jul 20 '05 #4
Oh I got it never mind it was anothe line continuation issue.

--
George Hester
_______________ _______________ ____
"George Hester" <he********@hot mail.com> wrote in message news:ta******** ************@tw ister.nyroc.rr. com...
Hello again Matin. I tried the ComputedStyle one you gave. After fixing for line continuation issues in my newsreader I am getting undefined for both alerts. Is there something wrong with it? Here is what you had and what I put it to that is removing the line continuation issues.

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getComputedStyl eForElement (element, cssPropertyName ) {
if (element) {
if (window.getComp utedStyle) {
return window.getCompu tedStyle(elemen t,'').getProper tyValue(cssProp ertyName.replac e(/([A-Z])/g, "-$1").toLowerCas e());
}
else if (element.curren tStyle) {
return element.current Style[cssPropertyName];
}
else {
return null;
}
}
else {
return null;
}
}

function getComputedStyl eForId (elementId, cssPropertyName ) {
if (document.getEl ementById) {
return
getComputedStyl eForElement(doc ument.getElemen tById(elementId ), cssPropertyName );
}
else {
return null;
}
}

function testComputedSty le () {
var ids = ['aDiv', 'aP'];
for (var i = 0; i < ids.length; i++) {
var cssValue = getComputedStyl eForId(ids[i], 'backgroundColo r');
if (cssValue === null) {
alert('Style background-color for id ' + ids[i] + ' not found.');
}
else {
alert('Computed style for background-color for id ' + ids[i] + ' is ' + cssValue);
}
}
}
</script>
</head>
<body onload="testCom putedStyle();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>

--
George Hester
_______________ _______________ ____
"Martin Honnen" <ma*******@yaho o.de> wrote in message news:3f******** @olaf.komtel.ne t...


George Hester wrote:
I have a css file this is a portion of it:

/* trackaccept.css */ div.track { width:400px; height: 100px; }

I have this in my ASP page:

<link rel="stylesheet " type="text/css"
href="/includes/trackaccept.css "/>

I need to read the values for width and height in my page. How do I
acess those values using JavaScipt? Thanks.

I have a length of 2 for CSS objects so I don't know whether it is 0
or 1 I'm assuming 0.since I don't have any other external CSS
statements. The other is declared in the page as <style></style>


Whether you have
<link rel="stylesheet "
or
<style type="text/css">
doesn't matter, browsers like IE4+ or Netscape 6+ and Mozilla support a
document.styleS heets
collection where each sheet appears.
You can access the CSS rules in the stylesheets and read and change
value of properties in a rule, unfortunately different in IE and
Netscape. IE has
document.styleS heets[i].rules[i].style.width
Netscape
document.styleS heets[i].cssRules[i].style.width

Here is an example:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getStyleObject (styleSheetInde x, ruleIndex) {
if (document.style Sheets) {
var styleSheet = document.styleS heets[styleSheetIndex];
if (styleSheet) {
var rule;
if (styleSheet.css Rules) {
rule = styleSheet.cssR ules[ruleIndex];
}
else if (styleSheet.rul es) {
rule = styleSheet.rule s[ruleIndex];
}
if (rule && rule.style) {
return rule.style;
}
else {
return null;
}
}
else {
return null;
}
}
else {
return null;
}
}

function testStyleSheet () {
var style = getStyleObject( 0, 0);
if (style) {
alert('style.he ight: ' + style.height);
}
else {
alert('style not found.');
}
}
</script>
</head>
<body onload="testSty leSheet();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>

Note that even Opera 7 doesn't support document.styleS heets. And I don't
know about Safari or Konqueror support, does anyone else care to check
and contribute?

Of course with external style sheets make sure you use <body onload
before trying to access them.

You can also check the selector of a rule with selectorText:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getStyleObjectF romSelector (selectorText) {
if (document.style Sheets) {
for (var i = document.styleS heets.length - 1; i >= 0; i--) {
var styleSheet = document.styleS heets[i];
var rules;
if (styleSheet.css Rules) {
rules = styleSheet.cssR ules;
}
else if (styleSheet.rul es) {
rules = styleSheet.rule s;
}
if (rules) {
for (var j = rules.length - 1; j >= 0; j--) {
if (rules[j].selectorText == selectorText) {
return rules[j].style;
}
}
}
}
return null;
}
else {
return null;
}
}

function testStyleSheet () {
var selectors = ['#aDiv', '.someClass'];
for (var i = 0; i < selectors.lengt h; i++) {
var selector = selectors[i];
var style = getStyleObjectF romSelector(sel ector);
if (style) {
alert('Selector ' + selector + ': style.height: ' + style.height);
}
else {
alert('No rule found for selector ' + selector);
}
}
}
</script>
</head>
<body onload="testSty leSheet();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>


Of course if you are looking for the computed style of an object there
is no need to read through style sheet rules, getComputedStyl e allows
that with Mozilla and with Opera 7 and element.current Style with IE5+:

<html>
<head>
<title>readin g out stylesheet information</title>
<style type="text/css">
#aDiv {
color: darkgreen;
background-color: lightgreen;
height: 200px;
}
</style>
<script type="text/javascript">
function getComputedStyl eForElement (element, cssPropertyName ) {
if (element) {
if (window.getComp utedStyle) {
return window.getCompu tedStyle(elemen t,
'').getProperty Value(cssProper tyName.replace(/([A-Z])/g,
"-$1").toLowerCas e());
}
else if (element.curren tStyle) {
return element.current Style[cssPropertyName];
}
else {
return null;
}
}
else {
return null;
}
}

function getComputedStyl eForId (elementId, cssPropertyName ) {
if (document.getEl ementById) {
return
getComputedStyl eForElement(doc ument.getElemen tById(elementId ),
cssPropertyName );
}
else {
return null;
}
}

function testComputedSty le () {
var ids = ['aDiv', 'aP'];
for (var i = 0; i < ids.length; i++) {
var cssValue = getComputedStyl eForId(ids[i], 'backgroundColo r');
if (cssValue === null) {
alert('Style background-color for id ' + ids[i] + ' not found.');
}
else {
alert('Computed style for background-color for id ' + ids[i] + '
is ' + cssValue);
}
}
}
</script>
</head>
<body onload="testCom putedStyle();">
<div id="aDiv">
<p>
Test.
</p>
</div>
</body>
</html>

Watch out for Netscape 7 and Opera 7 normalizing CSS values, for
instance color values are returned as rgb(r, g, b).
--

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

Jul 20 '05 #5
JRS: In article <zC************ ********@twiste r.nyroc.rr.com> , seen in
news:comp.lang. javascript, George Hester <he********@hot mail.com> posted
at Sat, 6 Dec 2003 18:55:27 :-
Lines: 256
Oh Martin thanks for that.

--
George Hester
______________ _______________ _____
"Martin Honnen" <ma*******@yaho o.de> wrote in message news:3f******** @olaf.komte
l.net...


George Hester wrote:
> I have a css file this is a portion of it:
> ...


*Plonk*. See FTI28, and c.l.j FAQ.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 20 '05 #6
What's your problem? Do you just hate helpful people or do you just hate in general?

--
George Hester
_______________ _______________ ____
"Dr John Stockton" <sp**@merlyn.de mon.co.uk> wrote in message news:u$******** ******@merlyn.d emon.co.uk...
JRS: In article <zC************ ********@twiste r.nyroc.rr.com> , seen in
news:comp.lang. javascript, George Hester <he********@hot mail.com> posted
at Sat, 6 Dec 2003 18:55:27 :-
Lines: 256


Oh Martin thanks for that.

--
George Hester
______________ _______________ _____
"Martin Honnen" <ma*******@yaho o.de> wrote in message news:3f******** @olaf.komte
l.net...


George Hester wrote:

> I have a css file this is a portion of it:
> ...


*Plonk*. See FTI28, and c.l.j FAQ.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

Jul 20 '05 #7
George Hester hu kiteb:
What's your problem? Do you just hate helpful people or do you just
hate in general?


I think his point is that requoting an extremely long post IN FULL just
to add a simple thank you is a waste of bandwidth. Most people here tend
to agree with that sentiment.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #8
6KB more then yours 2KB!!!. How much bandwidth did that run the Doctor? Funny place but I hear you will try to be more considerate in the future. Can't have too many six-pence spent needlessly now can we?

--
George Hester
_______________ _______________ ____
"Fabian" <la****@hotmail .com> wrote in message news:br******** *****@ID-174912.news.uni-berlin.de...
George Hester hu kiteb:
What's your problem? Do you just hate helpful people or do you just
hate in general?


I think his point is that requoting an extremely long post IN FULL just
to add a simple thank you is a waste of bandwidth. Most people here tend
to agree with that sentiment.


--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #9
George Hester wrote:
6KB more then yours 2KB!!!.
Your `!' key is borken.

Well, it sums up *and* it multiplies with every top-posting person.
[TOFU: Text Over, Fullquote Under / Top post]


*PLONK*
PointedEars
Jul 20 '05 #10

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

Similar topics

6
5127
by: Denis | last post by:
I am trying to launch an .mdb file via javascript. I do not need to do anything but open the application. It is able to open the application but for some reason it opens and then closes. At first I thought it may be a permission problem as far as writing the .ldb file to disk, but I added every single user and gave them write permissions to the folder and there is still no change. Has anyone been able to get this to work? Thanks in...
7
3291
by: George Hester | last post by:
Please take a look at this google artcle: http://groups.google.com/groups?hl=en&lr=&frame=right&th=55d6f4b50f5f9382&seekm=411f370d%241%40olaf.komtel.net#link9 The op was having trouble with access denied using resizeTo. I am having the same issue but the explanations in this article don't seem to apply here. I am not trying to resize a window with content from a different server. This issue lies here. What I do is make a popup...
4
9526
by: Lefteris | last post by:
Hi, I am trying to write a simple application in javascript that automatically fills the fields of a form in a page at another domain. I display the foreign domain page on a frame and have the javascript code in the parent (where the frameset is defined). I have set the "Access to data sources across domains" to "enable" in my security settings for the local intranet. The main frame page and the javascript is on the intranet. I even...
6
5244
by: Jon Davis | last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current browsers using: <object id="extendedhtml" type="text/html" data="otherpage.html" width="250" height="400"></object> My question is how do I access the document DOM of this object in Javascript? For example, "alert(extendedhtml.innerHTML);" doesn't work and produces an unknown error. I'd like to both read and write to the document's body element's innerHTML...
3
43945
by: Robert Oschler | last post by:
I know there isn't any $_POST array in Javascript, it exists on the server side accessible from PHP and other server side scripting languages. But I knew it would let you know specifically what data I'm after. Is there any way to get the data that is POSTED to a web page from client-side Javascript? Or does only the server get access to it? I can get access to the URL/href data from the "search" property, but that's because it's part...
7
402
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I access a property of an object using a string? ----------------------------------------------------------------------- There are two ways to access properties: the dot notation and the square bracket notation. What you are looking for is the square bracket notation in which the dot, and the identifier to its right, are replaced with a set of...
3
3460
by: SM | last post by:
Hello, Im trying to access elements in my XML file using the JavaScript DOM but i'm not sure how. I use AJAX to access the XML and then use the responseXML property to access the XML file data. I want to extract all the tracks from a specific CD. Right now, im using an array to stock all the data but its just a question of time before everything blows up because of the size of the array. Thats why im want to use an XML file (later i will...
10
2392
by: Stefan Weber | last post by:
Hi, I'm trying to access the JavaScript code contained in a <scripttag via its "text" attribute. This works well, if the code is embedded in the HTML page. However, when the code is in an external file with the "src" attribute, it does not work anymore. Does anybody have an idea if there is any way (be it clean and simple or as a workaround) to access the code of external scripts as well? I read, that if there is something like
7
2943
by: tshad | last post by:
How do you hide an asp.net object and still be able to access it? I had my email in a session variable, but you can't access the session variable from Javascript (I don't think - since Javascript is Client and Session is Server). I tried using the email that was on the page, but it was surrounded by a Panel that had its visible property set to false - so anything inside of the Panel was not on the page.
7
2022
by: JDOMPer | last post by:
Don’t misunderstand me – I use AJAX, but I think there is a far simpler, elegant alternative that just uses Javascript, the DOM and Php ( hence - JDOMP) for data transfers, and is cross-browser without the need for work arounds. JDOMP works in recent versions of Explorer, Mozilla, Safari and Opera. Please note I will not deal with security issues which are always an issue whenever there is access to a database. You can simply change text on...
0
8375
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...
1
8482
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7306
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...
1
6161
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
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
4149
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2714
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
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.