Hello,
I can't access the backgroundColor style in the DOM. Is there a problem with this property
Thank you.
Ré—ÂÂ檡.
<html>
<head>
<style>
#maDiv {
position : absolute;
top : 50px;
left : 50px;
height : 200px;
width : 100px;
background-color : #ABC;
}
</style>
</head>
<body>
<div id="maDiv">
azerty
</div>
<script language="javascript">
alert(document.getElementById("maDiv").style.backgroundColor);
</script>
</body>
</html>add this to your style tag:
type="text/css"
maybe that would workYou can only access properties in that way that you have defined them with JavaScript. If you want to access the background colour that has been defined in the actual CSS then you would have to use another method. Here is a function that you can use to grab styles with:function getStyle(el,styleProp){
var x = document.getElementById(el);
if (window.getComputedStyle){
var y = window.getComputedStyle(x,null).getPropertyValue(styleProp);
} else {
var y = x['currentStyle'][styleProp];
}
return y;
}The first wadge of code is for real browsers, and the second is for IE.Thank you very much.
Merci beaucoup.
Ré—ÂÂ檡.Doesn't that stink? I can't be the only one who thinks that's the pits, having to write a function to return a current style. Big hole in the technology there, imo.Lol. That's how I feel about compatibility & platforms. W3C should provide for us standard modules (external JS's) to do things like that for all browser.
Maybe after I create another hundred or so useful compatibility functions, I'll join them all into one JS file and call it something like CCI.js (Common Compatibility Interface).
Don't laugh, I'm highly skilled in JavaScript, as you all know, and well capable of doing such.And ever so humble too.
Joe, you wouldn't have to write a function for it, but IE sucks.
Ré—ÂÂ檡29, happy to help.
I can't access the backgroundColor style in the DOM. Is there a problem with this property
Thank you.
Ré—ÂÂ檡.
<html>
<head>
<style>
#maDiv {
position : absolute;
top : 50px;
left : 50px;
height : 200px;
width : 100px;
background-color : #ABC;
}
</style>
</head>
<body>
<div id="maDiv">
azerty
</div>
<script language="javascript">
alert(document.getElementById("maDiv").style.backgroundColor);
</script>
</body>
</html>add this to your style tag:
type="text/css"
maybe that would workYou can only access properties in that way that you have defined them with JavaScript. If you want to access the background colour that has been defined in the actual CSS then you would have to use another method. Here is a function that you can use to grab styles with:function getStyle(el,styleProp){
var x = document.getElementById(el);
if (window.getComputedStyle){
var y = window.getComputedStyle(x,null).getPropertyValue(styleProp);
} else {
var y = x['currentStyle'][styleProp];
}
return y;
}The first wadge of code is for real browsers, and the second is for IE.Thank you very much.
Merci beaucoup.
Ré—ÂÂ檡.Doesn't that stink? I can't be the only one who thinks that's the pits, having to write a function to return a current style. Big hole in the technology there, imo.Lol. That's how I feel about compatibility & platforms. W3C should provide for us standard modules (external JS's) to do things like that for all browser.
Maybe after I create another hundred or so useful compatibility functions, I'll join them all into one JS file and call it something like CCI.js (Common Compatibility Interface).
Don't laugh, I'm highly skilled in JavaScript, as you all know, and well capable of doing such.And ever so humble too.
Joe, you wouldn't have to write a function for it, but IE sucks.
Ré—ÂÂ檡29, happy to help.